This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
James Brooks
Gunslinger
Ranch Hand
Posts: 165
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
James Brooks
Gunslinger
Ranch Hand
Posts: 165
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bump
 
Jan Cumps
Bartender
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Brooks
Gunslinger
Ranch Hand
Posts: 165
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 165
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic