Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Null Pointer on servlet but not on stand alone  RSS feed

 
John McDonald
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I work on class InfoProvider as an utility class to access database and returns a list of ID. This class has a static method to perform my goal. It works fine in stand alone application. But when I inject it into a servlet. My servlet throws a Null pointer exception as follows:


"...type Exception report

message

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

exception

java.lang.NullPointerException
adserv.pdi.InfoProvider.getDocIDList(InfoProvider.java:42)
adserv.pdi.ADServlet.doGet(ADServlet.java:59)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.
..."


and my utility class:



Any suggestion is appreciated. Thanks.

John
[Edit by Dave - code tags added]
[ March 07, 2006: Message edited by: David O'Meara ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, I'd like to point out that "if (docIDList == null)" will never be true.
Then, could you tell which line is (InfoProvider.java:42) ?
 
Peter Sin
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have any oracle driver in your web application or application server ?
 
John McDonald
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks both of you. Peter, I think you bring out a good point. I run the query from a stand alone, it works fine. But when I run eclipse tool to debug it disappear my trace when I got to :

Class.forName("oracle.jdbc.driver.OracleDriver");
con= DriverManager.getConnection("jdbc racle:thin:@ecflab1:1521:ecfora", user,password);

But it bypass and yield the result without debugging.

=============================================
When I turn this code into servlet, I cut and paste JDBC code. I can got a connection but when I invoke connection.preparedStatement(..), It failed mysteriously. Thanks.

John
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have already been told to look at line 42. I predict that line 42 is this one:in which the dbConnection variable is null becausereturns null. And I predict that is the case because when you run it in the standalone version, your Oracle driver jar file is in your classpath but you didn't put it in your web application's classpath. The easiest way to do that is to put it in the WEB-INF/lib directory of your web application.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!