• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Close Connections made In Servlet

 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always close connections in a finally block.
 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Always close connections in a finally block.


How would this be fired if page is closed abnormally?
 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Always close connections in a finally block.


here is an example of my servlet code

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally blocks are always called. That is why you use them.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, Paul is correct


 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic