Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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: 3639
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!