當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。