This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Init block in servlet and jdbc connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Init block in servlet and jdbc connection" Watch "Init block in servlet and jdbc connection" New topic
Author

Init block in servlet and jdbc connection

Srinivasa Dhamodharan
Greenhorn

Joined: Oct 17, 2000
Posts: 19
Hi! all,
In one of my Servlets if I have the JDBC connection in the doget method it connects and the connection stays till the program completion, But if I have it in the servlets init block,
and do some database operation in the doget method , the connection is lost and the connection pointer is pointing to null,
Can anybody tell me why is this happening.
Thanks in Advance
Pragya Prakash
Ranch Hand

Joined: Sep 18, 2000
Posts: 42
In all probability, the connection variable is going out of scope.
Check for the scope of the variable.
If that is alright, then I could help you if u give additional input and the code.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Init block in servlet and jdbc connection
 
Similar Threads
Getting Database Connection from Servlet
JDBC pooling, MVC, and OO newbie...
Connection Pool/servlet
java.sql.SQLException: Closed Connection
JDBC in JSP/Servlet question