当前位置: 首页>>代码示例>>Java>>正文


Java Statement.RETURN_GENERATED_KEYS属性代码示例

本文整理汇总了Java中java.sql.Statement.RETURN_GENERATED_KEYS属性的典型用法代码示例。如果您正苦于以下问题:Java Statement.RETURN_GENERATED_KEYS属性的具体用法?Java Statement.RETURN_GENERATED_KEYS怎么用?Java Statement.RETURN_GENERATED_KEYS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.sql.Statement的用法示例。


在下文中一共展示了Statement.RETURN_GENERATED_KEYS属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeUpdate

/**
 * <!-- 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.  The driver will ignore the
 * flag if the SQL statement
 * is not an <code>INSERT</code> statement, or an SQL statement able to return
 * auto-generated keys (the list of such statements is vendor-specific).
 * <!-- end generic documentation -->
 *
 * <!-- start release-specific documentation -->
 * <div class="ReleaseSpecificDocumentation">
 * <h3>HSQLDB-Specific Information:</h3> <p>
 *
 * Starting with version 2.0, HSQLDB supports returning generated columns
 * with single-row and multi-row INSERT, UPDATE and MERGE statements. <p>
 * If the table has an IDENTITY or GENERATED column(s) the values for these
 * columns are returned in the next call to getGeneratedKeys().
 *
 * </div>
 * <!-- end release-specific documentation -->
 * @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
 * <code>DELETE</code>; or an SQL statement that returns nothing,
 * such as a DDL statement.
 * (:JDBC4 clarification)
 *
 * @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 (1) the row count for SQL Data Manipulation Language (DML) statements
 *         or (2) 0 for SQL statements that return nothing
 *         (:JDBC4 clarification)
 *
 * @exception SQLException if a database access error occurs,
 *  this method is called on a closed <code>Statement</code>, the given
 *            SQL statement returns a <code>ResultSet</code> object, or
 *            the given constant is not one of those allowed
 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
 * this method with a constant of Statement.RETURN_GENERATED_KEYS
 * @since JDK 1.4, HSQLDB 1.7
 */
public synchronized int executeUpdate(String sql,
        int autoGeneratedKeys) throws SQLException {

    if (autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS
            && autoGeneratedKeys != Statement.NO_GENERATED_KEYS) {
        throw JDBCUtil.invalidArgument("autoGeneratedKeys");
    }
    fetchResult(sql, StatementTypes.RETURN_COUNT, autoGeneratedKeys, null,
                null);

    if (resultIn.isError()) {
        throw JDBCUtil.sqlException(resultIn);
    }

    return resultIn.getUpdateCount();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:60,代码来源:JDBCStatement.java

示例2: executeUpdate

/**
     * <!-- 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.  The driver will ignore the
     * flag if the SQL statement
     * is not an <code>INSERT</code> statement, or an SQL statement able to return
     * auto-generated keys (the list of such statements is vendor-specific).
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * Starting with 1.9.0, HSQLDB supports this feature.
     *
     * </div>
     * <!-- end release-specific documentation -->
     * @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
     * <code>DELETE</code>; or an SQL statement that returns nothing,
     * such as a DDL statement.
     * (:JDBC4 clarification)
     *
     * @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 (1) the row count for SQL Data Manipulation Language (DML) statements
     *         or (2) 0 for SQL statements that return nothing
     *         (:JDBC4 clarification)
     *
     * @exception SQLException if a database access error occurs,
     *  this method is called on a closed <code>Statement</code>, the given
     *            SQL statement returns a <code>ResultSet</code> object, or
     *            the given constant is not one of those allowed
     * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
     * this method with a constant of Statement.RETURN_GENERATED_KEYS
     * @since JDK 1.4, HSQLDB 1.7
     */
//#ifdef JAVA4
    public synchronized int executeUpdate(String sql,
            int autoGeneratedKeys) throws SQLException {

        if (autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS
                && autoGeneratedKeys != Statement.NO_GENERATED_KEYS) {
            throw Util.invalidArgument("autoGeneratedKeys");
        }
        fetchResult(sql, StatementTypes.RETURN_COUNT, autoGeneratedKeys, null,
                    null);

        if (resultIn.isError()) {
            throw Util.sqlException(resultIn);
        }

        return resultIn.getUpdateCount();
    }
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:58,代码来源:JDBCStatement.java

示例3: executeUpdate

/**
     * <!-- 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.  The driver will ignore the
     * flag if the SQL statement
     * is not an <code>INSERT</code> statement, or an SQL statement able to return
     * auto-generated keys (the list of such statements is vendor-specific).
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * Starting with version 2.0, HSQLDB supports returning generated columns
     * with single-row and multi-row INSERT, UPDATE and MERGE statements. <p>
     * If the table has an IDENTITY or GENERATED column(s) the values for these
     * columns are returned in the next call to getGeneratedKeys().
     *
     * </div>
     * <!-- end release-specific documentation -->
     * @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
     * <code>DELETE</code>; or an SQL statement that returns nothing,
     * such as a DDL statement.
     * (:JDBC4 clarification)
     *
     * @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 (1) the row count for SQL Data Manipulation Language (DML) statements
     *         or (2) 0 for SQL statements that return nothing
     *         (:JDBC4 clarification)
     *
     * @exception SQLException if a database access error occurs,
     *  this method is called on a closed <code>Statement</code>, the given
     *            SQL statement returns a <code>ResultSet</code> object, or
     *            the given constant is not one of those allowed
     * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
     * this method with a constant of Statement.RETURN_GENERATED_KEYS
     * @since JDK 1.4, HSQLDB 1.7
     */
//#ifdef JAVA4
    public synchronized int executeUpdate(String sql,
            int autoGeneratedKeys) throws SQLException {

        if (autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS
                && autoGeneratedKeys != Statement.NO_GENERATED_KEYS) {
            throw JDBCUtil.invalidArgument("autoGeneratedKeys");
        }
        fetchResult(sql, StatementTypes.RETURN_COUNT, autoGeneratedKeys, null,
                    null);

        if (resultIn.isError()) {
            throw JDBCUtil.sqlException(resultIn);
        }

        return resultIn.getUpdateCount();
    }
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:61,代码来源:JDBCStatement.java

示例4: execute

/**
 * <!-- start generic documentation -->
 * 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 <code>INSERT</code> statement, or an SQL statement able to return
 * (JDBC4 clarification)
 * auto-generated keys (the list of such statements is vendor-specific).
 * <P>
 * In some (uncommon) situations, a single SQL statement may return
 * multiple result sets and/or update counts.  Normally you can ignore
 * this unless you are (1) executing a stored procedure that you know may
 * return multiple results or (2) you are dynamically executing an
 * unknown SQL string.
 * <P>
 * The <code>execute</code> method executes an SQL statement and indicates the
 * form of the first result.  You must then use the methods
 * <code>getResultSet</code> or <code>getUpdateCount</code>
 * to retrieve the result, and <code>getMoreResults</code> to
 * move to any subsequent result(s).
 * <!-- end generic documentation -->
 *
 * <!-- start release-specific documentation -->
 * <div class="ReleaseSpecificDocumentation">
 * <h3>HSQLDB-Specific Information:</h3> <p>
 *
 * Starting with 2.0, HSQLDB supports this feature.
 *
 * </div>
 * <!-- end release-specific documentation -->
 *
 * @param sql any SQL statement
 * @param autoGeneratedKeys a constant indicating whether auto-generated
 *        keys should be made available for retrieval using the method
 *        <code>getGeneratedKeys</code>; one of the following constants:
 *        <code>Statement.RETURN_GENERATED_KEYS</code> or
 *        <code>Statement.NO_GENERATED_KEYS</code>
 * @return <code>true</code> if the first result is a <code>ResultSet</code>
 *         object; <code>false</code> if it is an update count or there are
 *         no results
 * @exception SQLException if a database access error occurs,
 * this method is called on a closed <code>Statement</code> or the second
 *         parameter supplied to this method is not
 *         <code>Statement.RETURN_GENERATED_KEYS</code> or
 *         <code>Statement.NO_GENERATED_KEYS</code>.
 * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
 * this method with a constant of Statement.RETURN_GENERATED_KEYS
 * @see #getResultSet
 * @see #getUpdateCount
 * @see #getMoreResults
 * @see #getGeneratedKeys
 * @since JDK 1.4, HSQLDB 1.7
 */
public synchronized boolean execute(
        String sql, int autoGeneratedKeys) throws SQLException {

    if (autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS
            && autoGeneratedKeys != Statement.NO_GENERATED_KEYS) {
        throw JDBCUtil.invalidArgument("autoGeneratedKeys");
    }
    fetchResult(sql, StatementTypes.RETURN_ANY, autoGeneratedKeys, null,
                null);

    return resultIn.isData();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:66,代码来源:JDBCStatement.java

示例5: execute

/**
     * <!-- start generic documentation -->
     * 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 <code>INSERT</code> statement, or an SQL statement able to return
     * (JDBC4 clarification)
     * auto-generated keys (the list of such statements is vendor-specific).
     * <P>
     * In some (uncommon) situations, a single SQL statement may return
     * multiple result sets and/or update counts.  Normally you can ignore
     * this unless you are (1) executing a stored procedure that you know may
     * return multiple results or (2) you are dynamically executing an
     * unknown SQL string.
     * <P>
     * The <code>execute</code> method executes an SQL statement and indicates the
     * form of the first result.  You must then use the methods
     * <code>getResultSet</code> or <code>getUpdateCount</code>
     * to retrieve the result, and <code>getMoreResults</code> to
     * move to any subsequent result(s).
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * Starting with 1.9.0, HSQLDB supports this feature.
     *
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @param sql any SQL statement
     * @param autoGeneratedKeys a constant indicating whether auto-generated
     *        keys should be made available for retrieval using the method
     *        <code>getGeneratedKeys</code>; one of the following constants:
     *        <code>Statement.RETURN_GENERATED_KEYS</code> or
     *        <code>Statement.NO_GENERATED_KEYS</code>
     * @return <code>true</code> if the first result is a <code>ResultSet</code>
     *         object; <code>false</code> if it is an update count or there are
     *         no results
     * @exception SQLException if a database access error occurs,
     * this method is called on a closed <code>Statement</code> or the second
     *         parameter supplied to this method is not
     *         <code>Statement.RETURN_GENERATED_KEYS</code> or
     *         <code>Statement.NO_GENERATED_KEYS</code>.
     * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
     * this method with a constant of Statement.RETURN_GENERATED_KEYS
     * @see #getResultSet
     * @see #getUpdateCount
     * @see #getMoreResults
     * @see #getGeneratedKeys
     * @since JDK 1.4, HSQLDB 1.7
     */
//#ifdef JAVA4
    public synchronized boolean execute(
            String sql, int autoGeneratedKeys) throws SQLException {

        if (autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS
                && autoGeneratedKeys != Statement.NO_GENERATED_KEYS) {
            throw Util.invalidArgument("autoGeneratedKeys");
        }
        fetchResult(sql, StatementTypes.RETURN_ANY, autoGeneratedKeys, null,
                    null);

        return resultIn.isData();
    }
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:67,代码来源:JDBCStatement.java

示例6: execute

/**
     * <!-- start generic documentation -->
     * 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 <code>INSERT</code> statement, or an SQL statement able to return
     * (JDBC4 clarification)
     * auto-generated keys (the list of such statements is vendor-specific).
     * <P>
     * In some (uncommon) situations, a single SQL statement may return
     * multiple result sets and/or update counts.  Normally you can ignore
     * this unless you are (1) executing a stored procedure that you know may
     * return multiple results or (2) you are dynamically executing an
     * unknown SQL string.
     * <P>
     * The <code>execute</code> method executes an SQL statement and indicates the
     * form of the first result.  You must then use the methods
     * <code>getResultSet</code> or <code>getUpdateCount</code>
     * to retrieve the result, and <code>getMoreResults</code> to
     * move to any subsequent result(s).
     * <!-- end generic documentation -->
     *
     * <!-- start release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * Starting with 2.0, HSQLDB supports this feature.
     *
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @param sql any SQL statement
     * @param autoGeneratedKeys a constant indicating whether auto-generated
     *        keys should be made available for retrieval using the method
     *        <code>getGeneratedKeys</code>; one of the following constants:
     *        <code>Statement.RETURN_GENERATED_KEYS</code> or
     *        <code>Statement.NO_GENERATED_KEYS</code>
     * @return <code>true</code> if the first result is a <code>ResultSet</code>
     *         object; <code>false</code> if it is an update count or there are
     *         no results
     * @exception SQLException if a database access error occurs,
     * this method is called on a closed <code>Statement</code> or the second
     *         parameter supplied to this method is not
     *         <code>Statement.RETURN_GENERATED_KEYS</code> or
     *         <code>Statement.NO_GENERATED_KEYS</code>.
     * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
     * this method with a constant of Statement.RETURN_GENERATED_KEYS
     * @see #getResultSet
     * @see #getUpdateCount
     * @see #getMoreResults
     * @see #getGeneratedKeys
     * @since JDK 1.4, HSQLDB 1.7
     */
//#ifdef JAVA4
    public synchronized boolean execute(
            String sql, int autoGeneratedKeys) throws SQLException {

        if (autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS
                && autoGeneratedKeys != Statement.NO_GENERATED_KEYS) {
            throw JDBCUtil.invalidArgument("autoGeneratedKeys");
        }
        fetchResult(sql, StatementTypes.RETURN_ANY, autoGeneratedKeys, null,
                    null);

        return resultIn.isData();
    }
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:67,代码来源:JDBCStatement.java

示例7: PreparedStatementCreator

/**
 *
 * @param sql an SQL statement that may contain one or more '?' IN
 *        parameter placeholders
 * @param args sql  more '?' IN parameter
 * @param autoGeneratedKey      a flag indicating whether auto-generated keys
 *        should be returned; one of
 *        true <code>Statement.RETURN_GENERATED_KEYS</code> or
 *        false <code>Statement.NO_GENERATED_KEYS</code>
 */
public PreparedStatementCreator(String sql, boolean autoGeneratedKey, Object... args) {
    Assert.notNull(sql, "SQL must not be null");
    this.sql = sql;
    this.autoGeneratedKey = autoGeneratedKey ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS ;
    this.args = args;
}
 
开发者ID:egzosn,项目名称:spring-jdbc-orm,代码行数:16,代码来源:PreparedStatementCreator.java


注:本文中的java.sql.Statement.RETURN_GENERATED_KEYS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。