title: What's the best practice for JDBC connection/resultset/statement
body: <p>I am wondering what is the best practice for the following code snippet, do I have to close all stmt and rs everytime the executeQuery is done inside each 'if' or can I do just like now, close rs and stmt at the end of runOnSqlServer, and close connection at the end fo run method? Thanks for any pointers!</p>
  
  <pre><code>public void runOnSqlServer(Connection con, String[] params, String db){
      try{
      Statement stmt = con.createStatement();
      ResultSet rs = null;
      if(isVer){
          rs = stmt.executeQuery(micro_verSql);
          commonAct(rs, getParameter("isVer"), 1);
      } 
      if(isInfo){
          rs = stmt.executeQuery("SELECT DATABASEPROPERTYEX('"+db+"', 'COLLATION')");
          commonAct(rs, getParameter("isInfo"), 1);
      }
      }catch(SQLException){
      .....
      }finally{
      stmt.close();
      rs.close();
      }
  }
  
  public void run(CommandContext ctx) {
      try{
          ...
          runOnSqlServer(con, params, sqldb);
          ...
      }catch(Exception ex){
      }finally{
           if (con != null) con.close();
      }
  }
  </code></pre>