aspose file tools*
The moose likes Servlets and the fly likes Getting SQLException and NullPointerException while trying to access DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting SQLException and NullPointerException while trying to access DB " Watch "Getting SQLException and NullPointerException while trying to access DB " New topic
Author

Getting SQLException and NullPointerException while trying to access DB

adil ibnashraf
Greenhorn

Joined: Aug 27, 2010
Posts: 10
Hi,
Currently i am using ecllipse galileo 3.5.2 , Java-Open-JDK-1.6, Tomcat 6.0.29 as app server,Oracle 10g XE DB in Ubuntu 10.10. I am running a sample servlet to list the employee details from the DB.I have set the configuration parameters in Deployment Descriptor for the connection str,user id and password to access the DB.


I am accessing these parameters through the following code in the servlet .



But i am getting the following Exceptions in the Console on executing the Servlet -



I tried checking out the Marked errors in Markers window in eclipse and tried again . Then also the same above exceptions are coming but the output is getting printed to the browser.



-> And also another point that i wanted to know is -> How to get sample data for tables like EMPLOYEE in Oracle 10G XE as there is no sample data present for it when i searched for data in the DB?

Any solution to the query will be utmost helpful


Regards

Adil Hussain
- I want to speak Java


Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Did you do a println do make sure the "connStr" is being read in from the context parameter?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
adil ibnashraf
Greenhorn

Joined: Aug 27, 2010
Posts: 10
I printed the values . Getting null null null on giving prints


Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

That means you have a Servlet question and not a JDBC problem. Moving to the servlets forum.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Isn't the ServletContext where one gets the initialization parameters?

So you would do:
adil ibnashraf
Greenhorn

Joined: Aug 27, 2010
Posts: 10
Sorry , being a newbie i have not got much idea what to post where, Anyways - I have resolved that issue by giving the url,user-id,password in <init-param> section of the servlet in web.xml but still need to know why setting the same values in context-param section dint work . Will check that out in servlet forum .
adil ibnashraf
Greenhorn

Joined: Aug 27, 2010
Posts: 10
Ok will check by giving ServletContext in init() function
adil ibnashraf
Greenhorn

Joined: Aug 27, 2010
Posts: 10
Yippie !!! Initializing the connection str,user id and passwd with servlet context variables has resolved the issue.



Now the values are clearly coming without exception

 
Consider Paul's rocket mass heater.
 
subject: Getting SQLException and NullPointerException while trying to access DB