Hi,
The following program is
servlet with
Jdbc connection.
Iam using oracle 9i as databse.
There are no errors while compiling.
When i run on
tomcat server
http://localhost/servlet/servletwithjdbc iam not getting any thing on explorer.
Iam getting empty page.
How can i run this program to get results.
Program:
import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class servletwithjdbc extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter out=null;
Connection con=null;
con=connect();
Statement stmt=null;
ResultSet rs=null;
resp.setContentType("text/html");
out=resp.getWriter();
try
{
stmt=con.createStatement();
rs=stmt.executeQuery("select ename,job from scott.emp ");
out.println("<HTML><HEAD><TITLE>EMPDETAILS</TITLE><HEAD>");
out.println("<BODY>");
out.println("<UL>");
while(rs.next())
{
out.println("<L1>"+rs.getString("ename")+" "+rs.getString("job"));
}
out.println("</UL>");
out.println("</BODY></HTML>");
System.out.println("end iof listing");
}
catch(Exception e)
{
System.err.println("Exception:"+e.getMessage());
}
finally{
try
{
if(con!=null)
con.close();
}
catch(SQLException e)
{ }
}
}
protected static Connection connect()
{
String userID="SCOTT";
String password="TIGER";
Connection con=null;
String url="jdbc
racle:thin:@localhost:1521:bachi";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection(url,userID,password);
}
catch (Exception e)
{
System.err.println("Ecception: "+e.getMessage());
}
return con;
}
}
Thanks for your help.
--Lakshmi