aspose file tools*
The moose likes JDBC and the fly likes How to Close Connections made In Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to Close Connections made In Servlet" Watch "How to Close Connections made In Servlet" New topic
Author

How to Close Connections made In Servlet

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
I make a request to servlet which contains code to get a connection to a remote database, assign resultset data to an array, close connection, then display that array in a form. What happens if the user makes the request then closes the browser before the data is received and the close connection is never called. How can I make sure the close connection is aways ran if a connection is made?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Always close connections in a finally block.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
Paul Sturrock wrote:Always close connections in a finally block.


How would this be fired if page is closed abnormally?
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
Paul Sturrock wrote:Always close connections in a finally block.


here is an example of my servlet code

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Finally blocks are always called. That is why you use them.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 726
hi, Paul is correct


Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
Farakh khan wrote:hi, Paul is correct




Thanks,

I am going back and adding the finally method to my connection instances(all 591 of them).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Close Connections made In Servlet
 
Similar Threads
how to know how many data transferred - HTTP connection
How must i "synchronize" my servlets?
is HTTP "connection-less" or "connection-based" for SCEA Exam??
DB connection from servlets
Populate Table Rows With Data from AJAX