GeeCON Prague 2014*
The moose likes JDBC and the fly likes I'm holding a connection open even though I close it? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "I Watch "I New topic
Author

I'm holding a connection open even though I close it?

James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
Hi all,

I'm connecting to a SQL Server 2008 DB, and my code is apparently holding connections open in the DB, as evidenced by the Activity Monitor (sleeping - waiting for command), and in reports - Activity All Sessions (Show as a connection, 'no active requests on the session'). I'm closing my ResultSet, my Statement, and my Connection. Is this not enough? I'm using, for example, the following code for DB access, if interested:


also:

also:


also:

also:


Hello. My name is Inigo Montoya. You killed my father. Prepare to die.
James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
Bump
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2501
    
    8

In your code, you don't close connections if exceptions occur.
You should not close a connection - and other jdbc resources - in the try{} block, but in the finally{} block.


OCUP UML fundamental and ITIL foundation
youtube channel
James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
Jan Cumps wrote:In your code, you don't close connections if exceptions occur.
You should not close a connection - and other jdbc resources - in the try{} block, but in the finally{} block.


This is true; I really didn't think about that. Thank you. I'm going to change it, but any idea why I'm holding these open, even though no exceptions are thrown?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2501
    
    8

Nothing I can see directly in your code.
But I can see that you call some unknown to us methods (e.g.: populateReadArray ) in your while loop. Have you checked what is happening there?

Do you use recursion in your program?
James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
Jan Cumps wrote:Nothing I can see directly in your code.
But I can see that you call some unknown to us methods (e.g.: populateReadArray ) in your while loop. Have you checked what is happening there?

Yeah, nothing funny that I see:


Jan Cumps wrote:
Do you use recursion in your program?


No, everything is iterative. (while and for with counters)
 
GeeCON Prague 2014
 
subject: I'm holding a connection open even though I close it?