title: JDBC when does Auto-Commit commit
body: <p>I am working on reducing deadlocks and it was pointed out to me that I should not use multiple queries with one connection because the transaction may not be committed and open, causing deadlocks. So in pseudo code, something like this:</p>
  
  <pre><code>try(Connection con = datasource.getConnection()) 
      {
          PreparedStatement stm1 = con.prepareStatement(getSQL());
          stm1.setString(1, owner);
          stm1.setTimestamp(2, Timestamp.valueOf(LocalDateTime.now()));
          stm1.setInt(3, count);
  
          int updateCount = stm1.executeUpdate();
          stm1.close();
  
  
          PreparedStatement stm2 = con.prepareStatement(getSQL2());
          stm2.setString(1, owner);
          ResultSet rs = stm2.executeQuery();
  
          List&lt;Object&gt; results = new ArrayList&lt;&gt;();
          while(rs.next()) {
              results.add(create(rs));
          }
  
          return results;
      } catch (SQLException e) {
          throw new RuntimeException("Failed to claim message",e);
      }
  </code></pre>
  
  <p>When does stm1 commit the transaction when auto-commit is set to true? </p>
  
  <p>Is it good practise to reuse a connection like that or should both statements use separate connections instead? </p>