• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Null Pointer on servlet but not on stand alone

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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) ?
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Nothing up my sleeve ... and ... presto! A tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic