⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdbcstatement.java

📁 一個Light Weighted的Java Database Engin 適合各個領域之Java數据庫編輯.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        checkClosed();

        if (isEscapeProcessing) {
            sql = connection.nativeSQL(sql);
        }

        if (batchResultOut == null) {
            batchResultOut = new Result(ResultConstants.BATCHEXECDIRECT,
                                        new int[]{ Types.VARCHAR }, 0);
        }

        batchResultOut.add(new Object[]{ sql });
    }

    /**
     * <!-- start generic documentation -->
     * Empties this <code>Statement</code> object's current list of
     * SQL commands.
     * <P>
     * <B>NOTE:</B>  This method is optional. <p>
     * <!-- start generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * Starting with HSQLDB 1.7.2, this feature is supported.
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @exception SQLException if a database access error occurs or the
     * driver does not support batch updates
     * @see #addBatch
     * @since JDK 1.2 (JDK 1.1.x developers: read the new overview
     *   for jdbcStatement)
     */
    public void clearBatch() throws SQLException {

        checkClosed();

        if (batchResultOut != null) {
            batchResultOut.clear();
        }
    }

    /**
     * <!-- start generic documentation -->
     * Submits a batch of commands to the database for execution and
     * if all commands execute successfully, returns an array of update counts.
     * The <code>int</code> elements of the array that is returned are ordered
     * to correspond to the commands in the batch, which are ordered
     * according to the order in which they were added to the batch.
     * The elements in the array returned by the method <code>executeBatch</code>
     * may be one of the following:
     * <OL>
     * <LI>A number greater than or equal to zero -- indicates that the
     * command was processed successfully and is an update count giving the
     * number of rows in the database that were affected by the command's
     * execution
     * <LI>A value of <code>SUCCESS_NO_INFO</code> -- indicates that the command was
     * processed successfully but that the number of rows affected is
     * unknown
     * <P>
     * If one of the commands in a batch update fails to execute properly,
     * this method throws a <code>BatchUpdateException</code>, and a JDBC
     * driver may or may not continue to process the remaining commands in
     * the batch.  However, the driver's behavior must be consistent with a
     * particular DBMS, either always continuing to process commands or never
     * continuing to process commands.  If the driver continues processing
     * after a failure, the array returned by the method
     * <code>BatchUpdateException.getUpdateCounts</code>
     * will contain as many elements as there are commands in the batch, and
     * at least one of the elements will be the following:
     * <P>
     * <LI>A value of <code>EXECUTE_FAILED</code> -- indicates that the command failed
     * to execute successfully and occurs only if a driver continues to
     * process commands after a command fails
     * </OL>
     * <P>
     * A driver is not required to implement this method.
     * The possible implementations and return values have been modified in
     * the Java 2 SDK, Standard Edition, version 1.3 to
     * accommodate the option of continuing to proccess commands in a batch
     * update after a <code>BatchUpdateException</code> obejct has been thrown. <p>
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * Starting with HSQLDB 1.7.2, this feature is supported. <p>
     *
     * HSQLDB stops execution of commands in a batch when one of the commands
     * results in an exception. The size of the returned array equals the
     * number of commands that were executed successfully.<p>
     *
     * When the product is built under the JAVA1 target, an exception
     * is never thrown and it is the responsibility of the client software to
     * check the size of the  returned update count array to determine if any
     * batch items failed.  To build and run under the JAVA2 target, JDK/JRE
     * 1.3 or higher must be used.
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @return an array of update counts containing one element for each
     * command in the batch.  The elements of the array are ordered according
     * to the order in which commands were added to the batch.
     * @exception SQLException if a database access error occurs or the
     * driver does not support batch statements. Throws
     * {@link java.sql.BatchUpdateException}
     * (a subclass of <code>java.sql.SQLException</code>) if one of the commands
     * sent  to the database fails to execute properly or attempts to return a
     * result set.
     * @since JDK 1.3 (JDK 1.1.x developers: read the new overview
     *   for jdbcStatement)
     */
    public int[] executeBatch() throws SQLException {

        int[]         updateCounts;
        int           batchCount;
        HsqlException he;

        checkClosed();
        connection.clearWarningsNoCheck();

        if (batchResultOut == null) {
            batchResultOut = new Result(ResultConstants.BATCHEXECDIRECT,
                                        new int[]{ Types.VARCHAR }, 0);
        }

        batchCount = batchResultOut.getSize();

        try {
            resultIn = connection.sessionProxy.execute(batchResultOut);
        } catch (HsqlException e) {
            batchResultOut.clear();

            throw Util.sqlException(e);
        }

        batchResultOut.clear();

        if (resultIn.mode == ResultConstants.ERROR) {
            Util.throwError(resultIn);
        }

        updateCounts = resultIn.getUpdateCounts();

//#ifdef JAVA2
        if (updateCounts.length != batchCount) {
            throw new BatchUpdateException("failed batch", updateCounts);
        }

//#endif JAVA2
        return updateCounts;
    }

    /**
     * <!-- start generic documentation -->
     * Retrieves the <code>Connection</code> object
     * that produced this <code>Statement</code> object. <p>
     * <!-- end generic documentation -->
     *
     * @return the connection that produced this statement
     * @exception SQLException if a database access error occurs
     * @since JDK 1.2 (JDK 1.1.x developers: read the new overview
     *    for jdbcStatement)
     */
    public Connection getConnection() throws SQLException {

        checkClosed();

        return connection;
    }

    //--------------------------JDBC 3.0-----------------------------

    /**
     * <!-- start generic documentation -->
     * Moves to this <code>Statement</code> object's next result, deals with
     * any current <code>ResultSet</code> object(s) according  to the instructions
     * specified by the given flag, and returns
     * <code>true</code> if the next result is a <code>ResultSet</code> object.
     *
     * <P>There are no more results when the following is true:
     * <PRE>
     *   <code>(!getMoreResults() && (getUpdateCount() == -1)</code>
     * </PRE> <p>
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * HSQLDB 1.7.2 does not support this feature. <p>
     *
     * Calling this method always throws an <code>SQLException</code>,
     * stating that the function is not supported.
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @param current one of the following <code>Statement</code>
     *     constants indicating what should happen to current
     *     <code>ResultSet</code> objects obtained using the method
     *     <code>getResultSet</code:
     *     <code>CLOSE_CURRENT_RESULT</code>,
     *     <code>KEEP_CURRENT_RESULT</code>, or
     *     <code>CLOSE_ALL_RESULTS</code>
     * @return <code>true</code> if the next result is a <code>ResultSet</code>
     *      object; <code>false</code> if it is an update count or there are no
     *      more results
     * @exception SQLException if a database access error occurs
     * @since JDK 1.4, HSQLDB 1.7
     * @see #execute
     */
//#ifdef JDBC3
    public boolean getMoreResults(int current) throws SQLException {
        throw Util.notSupported;
    }

//#endif JDBC3

    /**
     * <!-- start generic documentation -->
     * Retrieves any auto-generated keys created as a result of executing this
     * <code>Statement</code> object. If this <code>Statement</code> object did
     * not generate any keys, an empty <code>ResultSet</code>
     * object is returned. <p>
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * HSQLDB 1.7.2 does not support this feature. <p>
     *
     * Calling this method always throws an <code>SQLException</code>,
     * stating that the function is not supported.
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @return a <code>ResultSet</code> object containing the auto-generated key(s)
     *     generated by the execution of this <code>Statement</code> object
     * @exception SQLException if a database access error occurs
     * @since JDK 1.4, HSQLDB 1.7
     */
//#ifdef JDBC3
    public ResultSet getGeneratedKeys() throws SQLException {
        throw Util.notSupported;
    }

//#endif JDBC3

    /**
     * <!-- start generic documentation -->
     * Executes the given SQL statement and signals the driver with the
     * given flag about whether the
     * auto-generated keys produced by this <code>Statement</code> object
     * should be made available for retrieval. <p>
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * HSQLDB 1.7.2 does not support this feature. <p>
     *
     * Calling this method always throws an <code>SQLException</code>,
     * stating that the function is not supported.
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @param sql must be an SQL <code>INSERT</code>, <code>UPDATE</code> or
     *    <code>DELETE</code> statement or an SQL statement that
     *    returns nothing
     * @param autoGeneratedKeys a flag indicating whether auto-generated keys
     *    should be made available for retrieval;
     *     one of the following constants:
     *     <code>Statement.RETURN_GENERATED_KEYS</code>
     *     <code>Statement.NO_GENERATED_KEYS</code>
     * @return either the row count for <code>INSERT</code>, <code>UPDATE</code>
     *     or <code>DELETE</code> statements, or <code>0</code> for SQL
     *     statements that return nothing
     * @exception SQLException if a database access error occurs, the given
     *        SQL statement returns a <code>ResultSet</code> object, or
     *        the given constant is not one of those allowed
     * @since JDK 1.4, HSQLDB 1.7
     */
//#ifdef JDBC3
    public int executeUpdate(String sql,
                             int autoGeneratedKeys) throws SQLException {
        throw Util.notSupported;
    }

//#endif JDBC3

    /**
     * <!-- start generic documentation -->
     * Executes the given SQL statement and signals the driver that the
     * auto-generated keys indicated in the given array should be made available
     * for retrieval.  The driver will ignore the array if the SQL statement
     * is not an <code>INSERT</code> statement. <p>
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * HSQLDB 1.7.2 does not support this feature. <p>
     *
     * Calling this method always throws an <code>SQLException</code>,
     * stating that the function is not supported.
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @param sql an SQL <code>INSERT</code>, <code>UPDATE</code> or
     *    <code>DELETE</code> statement or an SQL statement that returns nothing,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -