File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 2491
    
    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: 2491
    
    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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I'm holding a connection open even though I close it?
 
Similar Threads
Can't declare a Sybase Cursor for StoredProcedures using Spring
Basic Java Help
java.sql.SQLException: Closed Connection
pls suggest me a good style of programming
Strange query results using Java, but OK w/SQLSVR Mgmt Studio