title: No operations after closed connection, bypassing my check for a closed connection?
body: <p>I have code that loops through a queue of objects that describe information needing to be stored in a MySQL db. I recently changed the code a little to close connections in a <code>finally</code> block throughout the application so that we don't leak any when an exception occurs. It works great except:</p>
  
  <p>Some users sometimes see the error <code>No operations allowed after resultset closed</code> - I know what the error means but I can't figure out how it could be closed.</p>
  
  <p>The offending code:</p>
  
  <pre><code>    PreparedStatement s = null;
      Connection conn = null;
  
      try {
  
          if( !queue.isEmpty() ){
  
              conn = Prism.dbc();
              if(conn == null || conn.isClosed()){
                  return;
              }
              conn.setAutoCommit(false);
              s = conn.prepareStatement("INSERT query goes here");
              int i = 0;
              while (!queue.isEmpty()){
                  Handler a = queue.poll();
                  if( a == null || a.isCanceled() ) continue;
                  // .. value setting code here
                  s.addBatch();
                  if ((i + 1) % perBatch == 0) {
                      s.executeBatch(); // Execute every x items.
                  }
                  i++;
              }
  
              s.executeBatch();
              conn.commit();
  
          }
      } catch (SQLException e) {
          // error logging code
      } finally {
          if(s != null) try { s.close(); } catch (SQLException e) {}
          if(conn != null) try { conn.close(); } catch (SQLException e) {}
      }
  </code></pre>
  
  <p>The error points to the <code>conn.setAutoCommit(false);</code> line. However, I don't see how the connection could be closed at this point because I'm explicitly checking for a closed/null connection just above it.</p>