public static void setQueryTimeout(java.sql.Statement stmt, int timeout) throws SQLException {
    if (timeout < 0) {
      LOG.info("Invalid query timeout {}", timeout);
      return;
    }
    try {
      stmt.setQueryTimeout(timeout);
    } catch (SQLException e) {
      String message = e.getMessage() == null ? null : e.getMessage().toLowerCase();
      if (e instanceof SQLFeatureNotSupportedException ||
         (message != null && (message.contains("implemented") || message.contains("supported")))) {
        LOG.info("setQueryTimeout is not supported");
        return;
      }
      throw e;
    }
  }
Retry preparing a SQL statement with random backoff (same as the one implemented in HDFS-767).
This function only retries when the SQL query throws a SQLTransientException (which
might be able to succeed with a simple retry). It doesn't retry when the exception
is a SQLRecoverableException or SQLNonTransientException. For SQLRecoverableException
the caller needs to reconnect to the database and restart the whole transaction.

@param conn a JDBC connection.
@param stmt the SQL statement to be prepared.
@param waitWindow  The base time window (in milliseconds) before the next retry.
see {@link #getRandomWaitTime} for details.
@param maxRetries the maximum # of retries when getting a SQLTransientException.
@throws SQLException throws SQLRecoverableException or SQLNonTransientException the
first time it is caught, or SQLTransientException when the maxRetries has reached.
ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java