Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Should I close preparedStatement after each use?

843859Aug 20 2008 — edited Aug 23 2008
Hi

I am using a PreparedStatement and I wonder if I should close it after each query I make with it. Or is it automatically closed when I assign a new query to it?
PreparedStatement pstmt = null;
ResultSet rs = null;

pstmt = con.prepareStatement("bla bla SQL query 1");
rs = pstmt.executeQuery();

// Should I write pstmt.close() here?

pstmt = con.prepareStatement("bla bla SQL query 2");
rs = pstmt.executeQuery();

}finally{pstmt.close()}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 20 2008
Added on Aug 20 2008
6 comments
2,527 views