File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes SQL Exception on refeshing the servlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Exception on refeshing the servlet." Watch "SQL Exception on refeshing the servlet." New topic

SQL Exception on refeshing the servlet.

Kavita Ghia
Ranch Hand

Joined: Oct 10, 2000
Posts: 91
Hello friends,
I have a servlet written which is making connection to my database(Ms Access)if it helps and then performing search query.
The connection is done in the init() method of the servlet and the query is executed in the doGet() method.If the search query contains the data then it displays the result else the message record not found.Now my problem is this-
the whole procedure is happening only once when my servlet is called for the first time.i.e. when my init method is invoked.Subsequently whenever I try to refresh the servlet for other search result I get an SQLException stating the "General Error".Basically it is not creating or executing the following:
Statement st=con.createStatement();.
Can anyone explain me the reason for such a weird behavior.
Thanking in advance,
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
What part is weird? You are creating the connection in the init() but what if the connection drops? Then since the init() is only run the first time the servlet is loaded into memory, the createStatement() won't have a valid connection to use to create a statement. And when do you close the connection?

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: SQL Exception on refeshing the servlet.
It's not a secret anymore!