Where to close java PreparedStatements and ResultSets?

后端 未结 13 2207
忘了有多久
忘了有多久 2020-11-29 02:26

Consider the code:

PreparedStatement ps = null;
ResultSet rs = null;
try {
  ps = conn.createStatement(myQueryString);
  rs = ps.executeQuery();
  // process         


        
13条回答
  •  北海茫月
    2020-11-29 02:57

    If your are using Java 7 you can use the improvements in the exception handling mechanisms in those classes that implement AutoCloseable (i.e. PreparedStatement, Resultset)

    You might also find this question interesting: Closing ResultSet in Java 7

提交回复
热议问题