Driver problem ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alex_Truss
Posted On:   Sunday, April 27, 2003 10:09 PM

I am just starting to play with JSP and encountered the problem I can't figure out so far. I've installed DB2 PE, SDK and Tomcat web server. My CLASSPATH contains D:IBMSQLLIBjavadb2java.zip I created SAMPLE database in DB2. Basic JSP to retrieve data causes java.lang.NullPointerException. <%@page import="java.sql.*"%> <% Connection con=null; try{ Class.forName("COM.ibm.db2.jdbc.app.DB2Driver"); con = DriverManager.getConnection("jdbc:db2:sample","",""); } catch(Exception e){ out.println(e.getMessage()); } ResultSet rs=null; Statement stmt=nul   More>>
			
I am just starting to play with JSP and encountered the problem I can't figure out so far.

I've installed DB2 PE, SDK and Tomcat web server.
My CLASSPATH contains D:IBMSQLLIBjavadb2java.zip
I created SAMPLE database in DB2.

Basic JSP to retrieve data causes java.lang.NullPointerException.


<%@page import="java.sql.*"%>

<%
Connection con=null;

try{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
con = DriverManager.getConnection("jdbc:db2:sample","","");
}
catch(Exception e){
out.println(e.getMessage());
}

ResultSet rs=null;
Statement stmt=null;

try {
stmt = con.createStatement();

String sql="SELECT * FROM EMPLOYEE ";
rs = stmt.executeQuery(sql);

while(rs.next()) {
out.println(rs.getString("EMPNO"));
}
rs.close();
stmt.close();
con.close();
}
catch (SQLException e) {
out.println(e.getMessage());
}
%>


ERROR INFO:
description
The server encountered an internal error () that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)

.........
root cause

java.lang.NullPointerException
at org.apache.jsp.test_connection_jsp._jspService(test_connection_jsp.java:67)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)


I will greatly appreciate any advices, which may help to locate the root of the problem.
Thank you.    <<Less

Re: Driver problem ?

Posted By:   Christopher_Koenigsberg  
Posted On:   Monday, April 28, 2003 07:08 AM

Well, the "root cause" tells you that you tried to dereference something which was null. Anytime you get a return value and then try to do something, call a method on the returned object, you need to make sure it's not null first.



The error supposedly occurs on line 67 of the generated Java source from your jsp, so take a look there (the .java is presumably in the Tomcat working temp dir, something like "jakarta-tomcat-4.1.24workStandalonelocalhostyourwebappname")

About | Sitemap | Contact