title: Reuse of ResultSet member variable in a multi-threaded environment
body: <p>I am implementing a code that uses JDBC driver.</p>
  
  <p>Below is the code that I made.</p>
  
  <pre><code>public class MysqlUtils {
      public Connection conn;
      public ResultSet rs;
      public PreparedStatement stmt;
  
      public MysqlUtils(String address, String id, String passwd) {
          try {
              conn = DriverManager.getConnection(address, id, passwd);
              stmt = null;
              rs = null;
          } catch (SQLException e) {
              // error management
          }
      }
  
      public void getSomeData(long id) {
          try {
              stmt = conn.prepareStatement("SELECT * FROM some_table");
              rs = stmt.executeQuery();
              rs.next();
              System.out.println(rs.getString("some_column");
          } catch (SQLException e) {
              // error management
          }
      }
  }
  </code></pre>
  
  <p>I have declared Connection conn, ResultSet rs, PreparedStatement stmt as member variables because somehow I thought that might help me enhance performance.</p>
  
  <p>I have a couple of questions.</p>
  
  <ol>
  <li><p>If I call getSomeData() consecutively, will stmt and rs be assigned new objects every time? </p></li>
  <li><p>Regardless of the answer to the question above, if I run this code in a multi-threaded environment(multiple threads using MysqlUtils class), will there be a mix-up because I didn't declare ResultSet rs in getSomeData()?</p></li>
  <li><p>Was declaring Connection conn, ResultSet rs, PreparedStatement stmt as member variables a bad choice? In other words, is my implementation of JDBC a viable one?</p></li>
  </ol>
  
  <p>Thanks for the help.</p>