Hi,
I am using Resin-1.2.3 engine to run my servlet and mysql database with mysql-jdbc
driverto connect to my database thru servlet ......but it shows following error
message when I run my servlet....
500 SERVLET EXCEPTION:
java.lang.NullPointerException
at Firstdb.doGet(Firstdb.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:83)
at com.caucho.server.http.Invocation.service(Invocation.java:296)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:121)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:238)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:157)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)
My servlet engine is running all other servlets without database connectivity
I hope many of you might have face this problem.....please help me in fixing this
prolbem...
I am copying my servlet here ....
public class Firstdb extends HttpServlet {
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
res.setContentType("text/html");
PrintWriter out= res.getWriter();
try {
//load driver
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
//get connection
con = DriverManager.getConnection("jdbc:mysql://localhost:8080/test");
//create statement
stmt = con.createStatement();
//execute an sql query
rs = stmt.executeQuery("SELECT * FROM employee");
out.println("<HTML><HEAD><TITLE>PHONE BOOK</TITLE></HEAD>");
out.println("BODY");
out.println("<UL>");
while(rs.next()) {
out.println("<LI>"+rs.getString(1)+" " + rs.getString(2) + " " +rs.getString(3));
}
out.println("</UL>");
out.println("</BODY></HTML>");
}
catch(ClassNotFoundException e) {
out.println("couldn't load database driver:" +e.getMessage());
}
catch(SQLException e) {
out.println("SQLException caught:"+e.getMessage());
}
catch(Exception e) {
out.println("unable to load driver");
}
try {
// rs.close();
// stmt.close();
con.close();
} catch (SQLException ignored) { }
}
}
Thanks
Scott Decosta