📄 embedstatement.java
字号:
* The queryTimeout limit is the number of seconds the driver will * wait for a Statement to execute. If the limit is exceeded a * SQLException is thrown. * * @return the current query timeout limit in seconds; zero means unlimited * @exception SQLException thrown on failure. */ public int getQueryTimeout() throws SQLException { // Currently Cloudscape does not support any sort of timeout, so always // return 0, which means that timeout is unlimited. return(0); } /** * The queryTimeout limit is the number of seconds the driver will * wait for a Statement to execute. If the limit is exceeded a * SQLException is thrown. * * @param seconds the new query timeout limit in seconds; zero means unlimited * @exception SQLException thrown on failure. */ public void setQueryTimeout(int seconds) throws SQLException { if (seconds != 0) throw Util.notImplemented("setQueryTimeout"); } /** * Cancel can be used by one thread to cancel a statement that * is being executed by another thread. * @exception SQLException thrown on failure. */ public void cancel() throws SQLException { throw Util.notImplemented("cancel"); } /** * The first warning reported by calls on this Statement is * returned. A Statment's execute methods clear its SQLWarning * chain. Subsequent Statement warnings will be chained to this * SQLWarning. * * <p>The warning chain is automatically cleared each time * a statement is (re)executed. * * <P><B>Note:</B> If you are processing a ResultSet then any * warnings associated with ResultSet reads will be chained on the * ResultSet object. * * @return the first SQLWarning or null * @exception SQLException thrown on failure. */ public SQLWarning getWarnings() throws SQLException { checkStatus(); return warnings; } /** * After this call getWarnings returns null until a new warning is * reported for this Statement. * @exception SQLException thrown on failure. */ public void clearWarnings() throws SQLException { checkStatus(); warnings = null; } /** * setCursorName defines the SQL cursor name that will be used by * subsequent Statement execute methods. This name can then be * used in SQL positioned update/delete statements to identify the * current row in the ResultSet generated by this statement. If * the database doesn't support positioned update/delete, this * method is a noop. * * <P><B>Note:</B> By definition, positioned update/delete * execution must be done by a different Statement than the one * which generated the ResultSet being used for positioning. Also, * cursor names must be unique within a Connection. * * @param name the new cursor name. */ public void setCursorName(String name) throws SQLException { checkStatus(); cursorName = name; } //----------------------- Multiple Results -------------------------- /** * Execute a SQL statement that may return multiple results. * Under some (uncommon) situations a single SQL statement may return * multiple result sets and/or update counts. Normally you can ignore * this, unless you're executing a stored procedure that you know may * return multiple results, or unless you're dynamically executing an * unknown SQL string. The "execute", "getMoreResults", "getResultSet" * and "getUpdateCount" methods let you navigate through multiple results. * * The "execute" method executes a SQL statement and indicates the * form of the first result. You can then use getResultSet or * getUpdateCount to retrieve the result, and getMoreResults to * move to any subsequent result(s). * * @param sql any SQL statement * @param executeQuery caller is executeQuery() * @param executeUpdate caller is executeUpdate() * * @return true if the first result is a ResultSet; false if it is an integer * @see #getResultSet * @see #getUpdateCount * @see #getMoreResults * @exception SQLException thrown on failure */ public boolean execute(String sql) throws SQLException { return execute(sql, false, false, JDBC30Translation.NO_GENERATED_KEYS, null, null); } private boolean execute(String sql, boolean executeQuery, boolean executeUpdate, int autoGeneratedKeys, int[] columnIndexes, String[] columnNames) throws SQLException { // if sql is null, raise an error if (sql == null) throw newSQLException(SQLState.NULL_SQL_TEXT); synchronized (getConnectionSynchronization()) { checkExecStatus(); checkIfInMiddleOfBatch(); clearResultSets(); // release the last statement executed, if any. setupContextStack(); // make sure there's context // try to remember the SQL statement in case anybody asks for it SQLText = sql; try { Activation activation; try { PreparedStatement preparedStatement = lcc.prepareInternalStatement(sql); activation = preparedStatement.getActivation(lcc, resultSetType == JDBC20Translation.TYPE_SCROLL_INSENSITIVE); checkRequiresCallableStatement(activation); } catch (Throwable t) { throw handleException(t); } // this is for a Statement execution activation.setSingleExecution(); //bug 4838 - save the auto-generated key information in activation. keeping this //information in lcc will not work work it can be tampered by a nested trasaction if (autoGeneratedKeys == JDBC30Translation.RETURN_GENERATED_KEYS) activation.setAutoGeneratedKeysResultsetInfo(columnIndexes, columnNames); return executeStatement(activation, executeQuery, executeUpdate); } finally { restoreContextStack(); } } } /** * JDBC 3.0 * * Executes the given SQL statement, which may return multiple * results, and signals the driver that any auto-generated keys * should be made available for retrieval. The driver will ignore * this signal if the SQL statement is not an INSERT statement. * * @param sql any SQL statement * @param autoGeneratedKeys - a constant indicating whether * auto-generated keys should be made available for retrieval using * the method getGeneratedKeys; one of the following constants: * Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS * @return rue if the first result is a ResultSet object; false if * it is an update count or there are no results * @exception SQLException if a database access error occurs */ public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { return execute(sql, false, false, autoGeneratedKeys, null, null); } /** * JDBC 3.0 * * Executes the given SQL statement, which may return multiple * results, and signals the driver that the auto-generated keys * indicated in the given array should be made available for retrieval. * This array contains the indexes of the columns in the target table * that contain the auto-generated keys that should be made available. * The driver will ignore the array if the given SQL statement is not an * INSERT statement. * * @param sql any SQL statement * @param columnIndexes - an array of the indexes of the columns in the * inserted row that should be made available for retrieval by a call to * the method getGeneratedKeys * @return rue if the first result is a ResultSet object; false if * it is an update count or there are no results * @exception SQLException if a database access error occurs */ public boolean execute(String sql, int[] columnIndexes) throws SQLException { throw Util.notImplemented("execute(String, int[])"); } /** * JDBC 3.0 * * Executes the given SQL statement, which may return multiple * results, and signals the driver that the auto-generated keys * indicated in the given array should be made available for retrieval. * This array contains the names of the columns in the target table * that contain the auto-generated keys that should be made available. * The driver will ignore the array if the given SQL statement is not an * INSERT statement. * * @param sql any SQL statement * @param columnNames - an array of the names of the columns in the * inserted row that should be made available for retrieval by a call to * the method getGeneratedKeys * @return rue if the first result is a ResultSet object; false if * it is an update count or there are no results * @exception SQLException if a database access error occurs */ public boolean execute(String sql, String[] columnNames) throws SQLException { throw Util.notImplemented("execute(String, String[])"); } /** * getResultSet returns the current result as a ResultSet. It * should only be called once per result. * * @return the current result as a ResultSet; null if the result * is an update count or there are no more results or the statement * was closed. * @see #execute */ public final java.sql.ResultSet getResultSet() throws SQLException { checkStatus(); return results; } /** * getUpdateCount returns the current result as an update count; * if the result is a ResultSet or there are no more results -1 * is returned. It should only be called once per result. * * <P>The only way to tell for sure that the result is an update * count is to first test to see if it is a ResultSet. If it is * not a ResultSet it is either an update count or there are no * more results. * * @return the current result as an update count; -1 if it is a * ResultSet or there are no more results * @see #execute */ public final int getUpdateCount() throws SQLException { checkStatus(); return updateCount; } /** * getMoreResults moves to a Statement's next result. It returns true if * this result is a ResultSet. getMoreResults also implicitly * closes any current ResultSet obtained with getResultSet. * * There are no more results when (!getMoreResults() && * (getUpdateCount() == -1) * * @return true if the next result is a ResultSet; false if it is * an update count or there are no more results * @see #execute * @exception SQLException thrown on failure. */ public final boolean getMoreResults() throws SQLException { return getMoreResults(JDBC30Translation.CLOSE_ALL_RESULTS); } ///////////////////////////////////////////////////////////////////////// // // JDBC 2.0 methods that are implemented here because EmbedPreparedStatement // and EmbedCallableStatement in Local20 need access to them, and those // classes extend their peer classes in Local, instead of EmbedStatement // in Local20 // // We do the same of JDBC 3.0 methods. ///////////////////////////////////////////////////////////////////////// /** * JDBC 2.0 * * Determine the result set type. * * @exception SQLException Feature not implemented for now. */ public final int getResultSetType() throws SQLException { checkStatus(); return resultSetType; } /** * JDBC 2.0 * * Give a hint as to the direction in which the rows in a result set * will be processed. The hint applies only to result sets created * using this Statement object. The default value is * ResultSet.FETCH_FORWARD. * * @param direction the initial direction for processing rows * @exception SQLException if a database-access error occurs or direction * is not one of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or * ResultSet.FETCH_UNKNOWN */ public void setFetchDirection(int direction) throws SQLException { checkStatus(); /* fetch direction is meaningless to us. we just save * it off if it is valid and return the current value if asked. */ if (direction == JDBC20Translation.FETCH_FORWARD || direction == JDBC20Translation.FETCH_REVERSE || direction == JDBC20Translation.FETCH_UNKNOWN ) { fetchDirection = direction; }else throw newSQLException(SQLState.INVALID_FETCH_DIRECTION, new Integer(direction)); } /** * JDBC 2.0 * * Determine the fetch direction. * * @return the default fetch direction * @exception SQLException if a database-access error occurs */ public int getFetchDirection() throws SQLException { checkStatus(); return fetchDirection; } /** * JDBC 2.0 * * Give the JDBC driver a hint as to the number of rows that should * be fetched from the database when more rows are needed. The number * of rows specified only affects result sets created using this * statement. If the value specified is zero, then the hint is ignored. * The default value is zero. * * @param rows the number of rows to fetch * @exception SQLException if a database-access error occurs, or the * condition 0 <= rows <= this.getMaxRows() is not satisfied. */ public void setFetchSize(int rows) throws SQLException { checkStatus(); if (rows < 0 || (this.getMaxRows() != 0 && rows > this.getMaxRows())) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -