| Author |
How to Close Connections made In Servlet
|
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1254
|
|
|
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: 1254
|
|
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: 1254
|
|
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: 672
|
|
hi, Paul is correct
|
 |
Steve Dyke
Ranch Hand
Joined: Nov 16, 2004
Posts: 1254
|
|
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).
|
 |
 |
|
|
subject: How to Close Connections made In Servlet
|
|
|