@SuppressWarnings({"unchecked"})
  public static void close(Statement statement) {
    log.tracef("Closing prepared statement [%s]", statement);

    try {
      // if we are unable to "clean" the prepared statement,
      // we do not close it
      try {
        if (statement.getMaxRows() != 0) {
          statement.setMaxRows(0);
        }
        if (statement.getQueryTimeout() != 0) {
          statement.setQueryTimeout(0);
        }
      } catch (SQLException sqle) {
        // there was a problem "cleaning" the prepared statement
        if (log.isDebugEnabled()) {
          log.debugf("Exception clearing maxRows/queryTimeout [%s]", sqle.getMessage());
        }
        // EARLY EXIT!!!
        return;
      }
      statement.close();
    } catch (SQLException e) {
      log.debugf("Unable to release JDBC statement [%s]", e.getMessage());
    } catch (Exception e) {
      // try to handle general errors more elegantly
      log.debugf("Unable to release JDBC statement [%s]", e.getMessage());
    }
  }
Example #2
0
 private void testJdbcQueryTimeout() throws SQLException {
   deleteDb("cancel");
   Connection conn = getConnection("cancel");
   Statement stat = conn.createStatement();
   assertEquals(0, stat.getQueryTimeout());
   stat.setQueryTimeout(1);
   assertEquals(1, stat.getQueryTimeout());
   Statement s2 = conn.createStatement();
   assertEquals(1, s2.getQueryTimeout());
   ResultSet rs =
       s2.executeQuery(
           "SELECT VALUE " + "FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME = 'QUERY_TIMEOUT'");
   rs.next();
   assertEquals(1000, rs.getInt(1));
   assertThrows(ErrorCode.STATEMENT_WAS_CANCELED, stat)
       .executeQuery("SELECT MAX(RAND()) " + "FROM SYSTEM_RANGE(1, 100000000)");
   stat.setQueryTimeout(0);
   stat.execute("SET QUERY_TIMEOUT 1100");
   // explicit changes are not detected except, as documented
   assertEquals(0, stat.getQueryTimeout());
   conn.close();
 }
 @Test(expected = SQLFeatureNotSupportedException.class)
 public void assertGetQueryTimeout() throws SQLException {
   actual.getQueryTimeout();
 }
Example #4
0
 @Override
 public int getQueryTimeout() throws SQLException {
   return stat.getQueryTimeout();
 }
Example #5
0
 public int getQueryTimeout() throws SQLException {
   return pst.getQueryTimeout();
 };
 @Override
 public int getQueryTimeout() throws SQLException {
   return rawStatement.getQueryTimeout();
 }