• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which Place to write Connection.close() and preparedstatement.close()

 
Balaji Venkatesan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new in JDBC ...Which Place to write conn.close() and pstmt.close() Help Me ....

 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Best bet regarding your question is in the finally block for every method.



Closing "should" be in order. Closing say the connection DOES NOT necessarily mean (the JVM) will close the statement or result set for you.

If you are working with Java 7 then you can use the try-with-resource to shorten your code. here for more info
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!