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

📄 jdbcpreparedstatement.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     */    public boolean execute() throws SQLException {        checkClosed();        connection.clearWarningsNoCheck();        resultIn = null;        try {            resultOut.setMaxRows(maxRows);            resultOut.setParameterData(parameterValues);            resultIn = connection.sessionProxy.execute(resultOut);        } catch (HsqlException e) {            throw Util.sqlException(e);        }        if (resultIn.isError()) {            Util.throwError(resultIn);        }        return resultIn.isData();    }    /**     * <!-- start generic documentation -->     * Executes the SQL query in this <code>PreparedStatement</code> object     * and returns the <code>ResultSet</code> object generated by the query.<p>     * <!-- end generic documentation -->     *     * @return a <code>ResultSet</code> object that contains the data produced     *    by the query; never <code>null</code>     * @exception SQLException if a database access error occurs or the SQL     *       statement does not return a <code>ResultSet</code> object     */    public ResultSet executeQuery() throws SQLException {        checkClosed();        connection.clearWarningsNoCheck();        checkIsRowCount(false);        checkParametersSet();        resultIn = null;        try {            resultOut.setMaxRows(maxRows);            resultOut.setParameterData(parameterValues);            resultIn = connection.sessionProxy.execute(resultOut);        } catch (HsqlException e) {            throw Util.sqlException(e);        }        if (resultIn.isError()) {            Util.throwError(resultIn);        } else if (!resultIn.isData()) {            String msg = "Expected but did not recieve a result set";            throw Util.sqlException(Trace.UNEXPECTED_EXCEPTION, msg);        }        return new jdbcResultSet(this, resultIn, connection.connProperties,                                 connection.isNetConn);    }    /**     * <!-- start generic documentation -->     * Executes the SQL statement in this <code>PreparedStatement</code>     * object, which must be an SQL <code>INSERT</code>,     * <code>UPDATE</code> or <code>DELETE</code> statement; or an SQL     * statement that returns nothing, such as a DDL statement.<p>     * <!-- end generic documentation -->     *     * @return either (1) the row count for <code>INSERT</code>,     *     <code>UPDATE</code>, or <code>DELETE</code>     *     statements or (2) 0 for SQL statements that     *     return nothing     * @exception SQLException if a database access error occurs or the SQL     *        statement returns a <code>ResultSet</code> object     */    public int executeUpdate() throws SQLException {        checkClosed();        connection.clearWarningsNoCheck();        checkIsRowCount(true);        checkParametersSet();        resultIn = null;        try {            resultOut.setParameterData(parameterValues);            resultIn = connection.sessionProxy.execute(resultOut);        } catch (HsqlException e) {            throw Util.sqlException(e);        }        if (resultIn.isError()) {            Util.throwError(resultIn);        } else if (resultIn.mode != ResultConstants.UPDATECOUNT) {            String msg = "Expected but did not recieve a row update count";            throw Util.sqlException(Trace.UNEXPECTED_EXCEPTION, msg);        }        return resultIn.getUpdateCount();    }    /**     * <!-- 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 {        if (batchResultOut == null) {            batchResultOut = new Result(ResultConstants.BATCHEXECUTE,                                        parameterTypes, statementID);        }        return super.executeBatch();    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to SQL <code>NULL</code>. <p>     *     * <B>Note:</B> You must specify the parameter's SQL type.<p>     * <!-- end generic documentation -->     *     * <!-- start release-specific documentation -->     * <div class="ReleaseSpecificDocumentation">     * <h3>HSQLDB-Specific Information:</h3> <p>     *     * HSQLDB ignores the sqlType argument.     * </div>     * <!-- end release-specific documentation -->     *     * @param paramIndex the first parameter is 1, the second is 2, ...     * @param sqlType the SQL type code defined in <code>java.sql.Types</code>     * @exception SQLException if a database access error occurs     */    public void setNull(int paramIndex, int sqlType) throws SQLException {        setParameter(paramIndex, null);    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given Java <code>boolean</code>     * value.  The driver converts this to an SQL <code>BIT</code> value     * when it sends it to the database.<p>     * <!-- end generic documentation -->     *     * <!-- start release-specific documentation -->     * <div class="ReleaseSpecificDocumentation">     * <h3>HSQLDB-Specific Information:</h3> <p>     *     * Since 1.7.2, HSQLDB uses the BOOLEAN type instead of BIT, as     * per SQL 200n (SQL 3).     * </div>     * <!-- end release-specific documentation -->     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value     * @exception SQLException if a database access error occurs     */    public void setBoolean(int parameterIndex,                           boolean x) throws SQLException {        Boolean b = x ? Boolean.TRUE                      : Boolean.FALSE;        setParameter(parameterIndex, b);    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given Java <code>byte</code> value.     * The driver converts this to an SQL <code>TINYINT</code> value when     * it sends it to the database.<p>     * <!-- end generic documentation -->     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value     * @exception SQLException if a database access error occurs     */    public void setByte(int parameterIndex, byte x) throws SQLException {        setIntParameter(parameterIndex, x);    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given Java <code>short</code>     * value. The driver converts this to an SQL <code>SMALLINT</code>     * value when it sends it to the database.<p>     * <!-- end generic documentation -->     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value     * @exception SQLException if a database access error occurs     */    public void setShort(int parameterIndex, short x) throws SQLException {        setIntParameter(parameterIndex, x);    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given Java <code>int</code> value.     * The driver converts this to an SQL <code>INTEGER</code> value when     * it sends it to the database.<p>     * <!-- end generic documentation -->     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value     * @exception SQLException if a database access error occurs     */    public void setInt(int parameterIndex, int x) throws SQLException {        setIntParameter(parameterIndex, x);    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given Java <code>long</code> value.     * The driver converts this to an SQL <code>BIGINT</code> value when     * it sends it to the database.<p>     * <!-- end generic documentation -->     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value     * @exception SQLException if a database access error occurs     */    public void setLong(int parameterIndex, long x) throws SQLException {        setLongParameter(parameterIndex, x);    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given Java <code>float</code> value.     * The driver converts this to an SQL <code>FLOAT</code> value when     * it sends it to the database.<p>     * <!-- end generic documentation -->     *     * <!-- start release-specific documentation -->     * <div class="ReleaseSpecificDocumentation">     * <h3>HSQLDB-Specific Information:</h3> <p>     *     * Since 1.7.1, HSQLDB handles Java positive/negative Infinity     * and NaN <code>float</code> values consistent with the Java Language     * Specification; these <em>special</em> values are now correctly stored     * to and retrieved from the database.     * </div>     * <!-- start release-specific documentation -->     *     * @param parameterIndex the first parameter is 1, the second is 2, ...     * @param x the parameter value     * @exception SQLException if a database access error occurs     */    public void setFloat(int parameterIndex, float x) throws SQLException {        setDouble(parameterIndex, (double) x);    }    /**     * <!-- start generic documentation -->     * Sets the designated parameter to the given Java <code>double</code> value.     * The driver converts this to an SQL <code>DOUBLE</code> value when it

⌨️ 快捷键说明

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