Exemplo n.º 1
0
 /**
  * Executes a query (select statement) and returns the result set. If another result set exists
  * for this statement, this will be closed (even if this statement fails).
  *
  * @param sql the SQL statement to execute
  * @return the result set
  */
 public ResultSet executeQuery(String sql) throws SQLException {
   try {
     int id = getNextId(TraceObject.RESULT_SET);
     if (isDebugEnabled()) {
       debugCodeAssign(
           "ResultSet", TraceObject.RESULT_SET, id, "executeQuery(" + quote(sql) + ")");
     }
     checkClosed();
     closeOldResultSet();
     sql = conn.translateSQL(sql, escapeProcessing);
     synchronized (session) {
       CommandInterface command = conn.prepareCommand(sql, fetchSize);
       ResultInterface result;
       boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
       boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
       setExecutingStatement(command);
       try {
         result = command.executeQuery(maxRows, scrollable);
       } finally {
         setExecutingStatement(null);
       }
       command.close();
       resultSet =
           new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
     }
     return resultSet;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
Exemplo n.º 2
0
 /**
  * Executes an arbitrary statement. If another result set exists for this statement, this will be
  * closed (even if this statement fails).
  *
  * <p>If the statement is a create or drop and does not throw an exception, the current
  * transaction (if any) is committed after executing the statement. If auto commit is on, and the
  * statement is not a select, this statement will be committed.
  *
  * @param sql the SQL statement to execute
  * @return true if a result set is available, false if not
  */
 public boolean execute(String sql) throws SQLException {
   try {
     int id = getNextId(TraceObject.RESULT_SET);
     if (isDebugEnabled()) {
       debugCodeCall("execute", sql);
     }
     checkClosedForWrite();
     closeOldResultSet();
     sql = conn.translateSQL(sql, escapeProcessing);
     CommandInterface command = conn.prepareCommand(sql, fetchSize);
     boolean returnsResultSet;
     synchronized (session) {
       setExecutingStatement(command);
       try {
         if (command.isQuery()) {
           returnsResultSet = true;
           boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
           boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
           ResultInterface result = command.executeQuery(maxRows, scrollable);
           resultSet =
               new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
         } else {
           returnsResultSet = false;
           updateCount = command.executeUpdate();
         }
       } finally {
         setExecutingStatement(null);
       }
     }
     command.close();
     return returnsResultSet;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }
 private int executeUpdateInternal(String sql) throws SQLException {
   checkClosedForWrite();
   try {
     closeOldResultSet();
     sql = JdbcConnection.translateSQL(sql, escapeProcessing);
     CommandInterface command = conn.prepareCommand(sql, fetchSize);
     synchronized (session) {
       setExecutingStatement(command);
       try {
         updateCount = command.executeUpdate();
       } finally {
         setExecutingStatement(null);
       }
     }
     command.close();
     return updateCount;
   } finally {
     afterWriting();
   }
 }
Exemplo n.º 4
0
 /**
  * Executes a statement (insert, update, delete, create, drop) and returns the update count. If
  * another result set exists for this statement, this will be closed (even if this statement
  * fails).
  *
  * <p>If the statement is a create or drop and does not throw an exception, the current
  * transaction (if any) is committed after executing the statement. If auto commit is on, this
  * statement will be committed.
  *
  * @param sql the SQL statement
  * @return the update count (number of row affected by an insert, update or delete, or 0 if no
  *     rows or the statement was a create, drop, commit or rollback)
  * @throws SQLException if a database error occurred or a select statement was executed
  */
 public int executeUpdate(String sql) throws SQLException {
   try {
     debugCodeCall("executeUpdate", sql);
     checkClosedForWrite();
     closeOldResultSet();
     sql = conn.translateSQL(sql, escapeProcessing);
     CommandInterface command = conn.prepareCommand(sql, fetchSize);
     synchronized (session) {
       setExecutingStatement(command);
       try {
         updateCount = command.executeUpdate();
       } finally {
         setExecutingStatement(null);
       }
     }
     command.close();
     return updateCount;
   } catch (Exception e) {
     throw logAndConvert(e);
   }
 }