I've got a very simple jsp page that calls a class method to return a ResultSet. The method calls another method in the same class to return a Connection. When run stand alone, everything within the class runs as expected.
But when called from the jsp, the Connection throws a NullPointerException.
The jsp:
Error:
[9/13/07 11:17:56:693 EDT] 69dcac7f SystemErr R java.lang.NullPointerException
[9/13/07 11:17:56:693 EDT] 69dcac7f SystemErr R at user.Employee.getEmployeeDetail(Employee.java:94)
[9/13/07 11:17:56:693 EDT] 69dcac7f SystemErr R at org.apache.jsp._EmployeeDetails._jspService(_EmployeeDetails.java:83)
[9/13/07 11:17:56:693 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
[9/13/07 11:17:56:693 EDT] 69dcac7f SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:669)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:767)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:983)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)[9/13/07 11:17:57:599 EDT] 69dcac7f WebGroup E SRVE0026E: [Servlet Error]-[]: java.lang.NullPointerException
at org.apache.jsp._EmployeeDetails._jspService(_EmployeeDetails.java:84)
at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:669)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:767)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:983)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
And the relevant parts of the Employee class:
I shouldn't have to reference the connection from the jsp, should I? It seems that the connection is relevant to the getEmployeeDetail and not the calling jsp, no?
Any insight is greatly appreciated.
But when called from the jsp, the Connection throws a NullPointerException.
The jsp:
Code:
Employee emp = new Employee();
ResultSet rs = null;
String fname ="";
String lname="";
try
{
rs= emp.getEmployeeDetail(1003);
if (rs.next())
{
fname = rs.getString("fname");
lname= rs.getString("lname");
}
else
{
System.out.println("Nothing here");
}
}
catch (SQLException e)
{
e.printStackTrace();
}
Error:
[9/13/07 11:17:56:693 EDT] 69dcac7f SystemErr R java.lang.NullPointerException
[9/13/07 11:17:56:693 EDT] 69dcac7f SystemErr R at user.Employee.getEmployeeDetail(Employee.java:94)
[9/13/07 11:17:56:693 EDT] 69dcac7f SystemErr R at org.apache.jsp._EmployeeDetails._jspService(_EmployeeDetails.java:83)
[9/13/07 11:17:56:693 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
[9/13/07 11:17:56:693 EDT] 69dcac7f SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:669)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:767)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:983)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
[9/13/07 11:17:56:708 EDT] 69dcac7f SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)[9/13/07 11:17:57:599 EDT] 69dcac7f WebGroup E SRVE0026E: [Servlet Error]-[]: java.lang.NullPointerException
at org.apache.jsp._EmployeeDetails._jspService(_EmployeeDetails.java:84)
at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:669)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:767)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:983)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
And the relevant parts of the Employee class:
Code:
public static Connection getCon()
{
Connection gConn=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
gConn= DriverManager.getConnection("jdbc:odbc:enfodex","sa","moab");
}
catch (SQLException se)
{
se.printStackTrace();
}
catch(ClassNotFoundException cnf)
{
cnf.printStackTrace();
}
finally
{
return gConn;
}
}
public static ResultSet getEmployeeDetail(int emp_id)
{
System.out.println("detail emp_id= " + emp_id);
ResultSet rs = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException cnf)
{
cnf.printStackTrace();
}
Connection con = getCon();
try
{
//###Line 94
if (!con.isClosed())
{
CallableStatement cs = con.prepareCall("{call sp_getEmployeeDetails(?)}");
cs.setInt(1,emp_id);
cs.execute();
rs = cs.getResultSet();
if(rs.next())
{
System.out.println(rs.getString("fname"));
}
}
else
{
System.out.println("no connection");
}
}
catch(SQLException se)
{
se.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
return rs;
}
I shouldn't have to reference the connection from the jsp, should I? It seems that the connection is relevant to the getEmployeeDetail and not the calling jsp, no?
Any insight is greatly appreciated.