title: Where to close a JDBC Connection while I want to return the ResultSet
body: <p>It seems that the <code>ResultSet</code> will be automatically closed when I close the <code>Connection</code>.
  But I want to return the <code>ResultSet</code> and use it in another method, then I don't know where to close <code>Connection</code> and <code>PreparedStatement</code>.</p>
  
  <pre><code>public ResultSet executeQuery(String sql, String[] getValue)
  {
      Connection conn = null;
      PreparedStatement pstmt = null;
      ResultSet rs = null;
      try
      {
          conn = getConn();
          pstmt = conn.prepareStatement(sql);
          if (getValue != null)
          {
              for (int i = 0; i &lt; getValue.length; i++)
              {
                  pstmt.setString(i + 1, getValue[i]);
              }
          }
          rs = pstmt.executeQuery();
      } catch (Exception e)
      {
          e.printStackTrace();
          closeAll(conn, pstmt, rs);
      }
      return rs;
  }
  </code></pre>
  
  <p>I've moved <code>closeAll(conn, pstmt, null);</code> into catch block because I found that if I put it in finally block I'll lost my <code>rs</code> immediately just before it returns.
  Now when I want to close the <code>rs</code>, I can't close the <code>conn</code> and <code>pstmt</code>. Is there any solution?</p>