java.sql.Statement#NO_GENERATED_KEYS源码实例Demo

下面列出了java.sql.Statement#NO_GENERATED_KEYS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gemfirexd-oss   文件: EmbedCallableStatement.java
/**
	 * @exception SQLException thrown on failure
	 * 
	 * Set rootID=0 and statementLevel=0
	 */
	public EmbedCallableStatement (EmbedConnection conn, String sql,
								   int resultSetType,
								   int resultSetConcurrency,
								   int resultSetHoldability,
								   long id, short execFlags)
		throws SQLException
	{
	    super(conn, sql, false, 
			  resultSetType,
			  resultSetConcurrency,
			  resultSetHoldability,
			  Statement.NO_GENERATED_KEYS,
			  null,
			  null,  id, execFlags, null, 0, 0);
// GemStone changes END

		// mark our parameters as for a callable statement 
		ParameterValueSet pvs = getParms();

		// do we have a return parameter?
		hasReturnOutputParameter = pvs.hasReturnOutputParameter();

		this.isNonCallableStatement = !hasReturnOutputParameter &&
		    !this.preparedStatement.isCallableStatement();
	}
 
源代码2 项目: sql-layer   文件: ExecuteAutoGeneratedKeys.java
static ExecuteAutoGeneratedKeys of(int autoGeneratedKeys) {
    switch (autoGeneratedKeys) {
    case Statement.NO_GENERATED_KEYS:
        return null;
    case Statement.RETURN_GENERATED_KEYS:
        return new ExecuteAutoGeneratedKeys() {
                @Override
                public List<Column> getTargetColumns(Table targetTable) {
                    Column identityColumn = targetTable.getIdentityColumn();
                    if (identityColumn == null)
                        return Collections.emptyList();
                    else
                        return Collections.singletonList(identityColumn);
                }
            };
    default:
        throw new IllegalArgumentException("Invalid autoGeneratedKeys: " + autoGeneratedKeys);
    }
}
 
源代码3 项目: gemfirexd-oss   文件: EmbedCallableStatement.java
/**
	 * @exception SQLException thrown on failure
	 * 
	 * Set rootID=0 and statementLevel=0
	 */
	public EmbedCallableStatement (EmbedConnection conn, String sql,
								   int resultSetType,
								   int resultSetConcurrency,
								   int resultSetHoldability,
								   long id, short execFlags)
		throws SQLException
	{
	    super(conn, sql, false, 
			  resultSetType,
			  resultSetConcurrency,
			  resultSetHoldability,
			  Statement.NO_GENERATED_KEYS,
			  null,
			  null,  id, execFlags, null, 0, 0);
// GemStone changes END

		// mark our parameters as for a callable statement 
		ParameterValueSet pvs = getParms();

		// do we have a return parameter?
		hasReturnOutputParameter = pvs.hasReturnOutputParameter();

		this.isNonCallableStatement = !hasReturnOutputParameter &&
		    !this.preparedStatement.isCallableStatement();
	}
 
源代码4 项目: jaybird   文件: GeneratedKeysSupportFactory.java
@Override
public Query buildQuery(String sql, int autoGeneratedKeys) throws SQLException {
    switch (autoGeneratedKeys) {
    case Statement.NO_GENERATED_KEYS:
        return GeneratedKeysQueryBuilder
                .create(parser, sql, supportedQueryTypes)
                .forNoGeneratedKeysOption();
    case Statement.RETURN_GENERATED_KEYS:
        return GeneratedKeysQueryBuilder
                .create(parser, sql, supportedQueryTypes)
                .forReturnGeneratedKeysOption(fbDatabaseMetaData);
    default:
        throw new FbExceptionBuilder()
                .nonTransientException(JaybirdErrorCodes.jb_invalidGeneratedKeysOption)
                .toFlatSQLException();
    }
}
 
源代码5 项目: snowflake-jdbc   文件: SnowflakeConnectionV1.java
@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
throws SQLException
{
  logger.debug(
      "PreparedStatement prepareStatement(String sql, "
      + "int autoGeneratedKeys)");

  if (autoGeneratedKeys == Statement.NO_GENERATED_KEYS)
  {
    return prepareStatement(sql);
  }

  throw new SQLFeatureNotSupportedException();
}
 
源代码6 项目: snowflake-jdbc   文件: SnowflakeStatementV1.java
@Override
public long executeLargeUpdate(String sql, int autoGeneratedKeys)
throws SQLException
{
  logger.debug("executeUpdate(String sql, int autoGeneratedKeys)");

  if (autoGeneratedKeys == Statement.NO_GENERATED_KEYS)
  {
    return executeLargeUpdate(sql);
  }
  else
  {
    throw new SQLFeatureNotSupportedException();
  }
}
 
源代码7 项目: mariadb-connector-j   文件: Results.java
/**
 * Single Text query. /! use internally, because autoincrement value is not right for
 * multi-queries !/
 */
public Results() {
  this.statement = null;
  this.fetchSize = 0;
  this.maxFieldSize = 0;
  this.batch = false;
  this.expectedSize = 1;
  this.cmdInformation = null;
  this.binaryFormat = false;
  this.resultSetScrollType = ResultSet.TYPE_FORWARD_ONLY;
  this.resultSetConcurrency = ResultSet.CONCUR_READ_ONLY;
  this.autoIncrement = 1;
  this.autoGeneratedKeys = Statement.NO_GENERATED_KEYS;
  this.sql = null;
}
 
源代码8 项目: ignite   文件: JdbcThinStatement.java
/** {@inheritDoc} */
@Override public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
    ensureNotClosed();

    switch (autoGeneratedKeys) {
        case Statement.RETURN_GENERATED_KEYS:
            throw new SQLFeatureNotSupportedException("Auto-generated columns are not supported.");

        case Statement.NO_GENERATED_KEYS:
            return executeUpdate(sql);

        default:
            throw new SQLException("Invalid autoGeneratedKeys value");
    }
}
 
源代码9 项目: jaybird   文件: GeneratedKeysSupportFactory.java
@Override
public Query buildQuery(String sql, int autoGeneratedKeys) throws SQLException {
    switch (autoGeneratedKeys) {
    case Statement.NO_GENERATED_KEYS:
        return new Query(false, sql);
    case Statement.RETURN_GENERATED_KEYS:
        throw disabled();
    default:
        throw new FbExceptionBuilder()
                .nonTransientException(JaybirdErrorCodes.jb_invalidGeneratedKeysOption)
                .toFlatSQLException();
    }
}
 
源代码10 项目: evosql   文件: JDBCStatement.java
/**
 * <!-- 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();
}
 
源代码11 项目: rxjava-jdbc   文件: QueryUpdateOnSubscribe.java
/**
 * Executes the prepared statement.
 * 
 * @param subscriber
 * 
 * @throws SQLException
 */
@SuppressWarnings("unchecked")
private void performUpdate(final Subscriber<? super T> subscriber, State state)
        throws SQLException {
    if (subscriber.isUnsubscribed()) {
        return;
    }
    if (query.context().batchSize() > 1 && !query.context().isTransactionOpen()) {
        throw new SQLRuntimeException("batching can only be performed within a transaction");
    }
    int keysOption;
    if (query.returnGeneratedKeys()) {
        keysOption = Statement.RETURN_GENERATED_KEYS;
    } else {
        keysOption = Statement.NO_GENERATED_KEYS;
    }
    state.ps = state.con.prepareStatement(query.sql(), keysOption);
    Util.setParameters(state.ps, parameters, query.names());

    if (subscriber.isUnsubscribed())
        return;

    int count;
    try {
        debug("executing sql={}, parameters {}", query.sql(), parameters);
        if (state.ps instanceof PreparedStatementBatch
                && parameters instanceof ArrayListFinal) {
            count = state.ps.executeUpdate();
            count += ((PreparedStatementBatch) state.ps).executeBatchRemaining();
        } else {
            count = state.ps.executeUpdate();
        }
        debug("executed ps={}", state.ps);
        if (query.returnGeneratedKeys()) {
            debug("getting generated keys");
            ResultSet rs = state.ps.getGeneratedKeys();
            debug("returned generated key result set {}", rs);
            state.rs = rs;
            Observable<Parameter> params = Observable.just(new Parameter(state));
            Observable<Object> depends = Observable.empty();
            Observable<T> o = new QuerySelect(QuerySelect.RETURN_GENERATED_KEYS, params,
                    depends, query.context(), query.context().resultSetTransform())
                            .execute(query.returnGeneratedKeysFunction());
            Subscriber<T> sub = createSubscriber(subscriber);
            o.unsafeSubscribe(sub);
        }
    } catch (SQLException e) {
        throw new SQLException("failed to execute sql=" + query.sql(), e);
    }
    if (!query.returnGeneratedKeys()) {
        // must close before onNext so that connection is released and is
        // available to a query that might process the onNext
        close(state);
        if (subscriber.isUnsubscribed())
            return;
        debug("onNext");
        subscriber.onNext((T) (Integer) count);
        complete(subscriber);
    }
}
 
源代码12 项目: evosql   文件: JDBCStatement.java
/**
 * <!-- 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();
}
 
源代码13 项目: gemfirexd-oss   文件: StatementKeyFactory.java
/**
 * Creates a key for a query with default settings.
 * <p>
 * Defaults are according to the JDBC standard; result set type will be
 * <code>ResultSet.TYPE_FORWARD_ONLY</code>, concurrency will be
 * <code>ResultSet.CONCUR_READ_ONLY</code> and the statement will not
 * return auto-generated keys.
 *
 * @param sql SQL query string
 * @param schema current compilation schema
 * @param holdability result set holdability
 * @return A statement key.
 */
public static StatementKey newPrepared(
        String sql, String schema, int holdability) {
    return new StatementKey(PREPARED, sql, schema,
            ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY,
            holdability, Statement.NO_GENERATED_KEYS);
}
 
源代码14 项目: gemfirexd-oss   文件: StatementKeyFactory.java
/**
 * Creates a key for a query with default settings.
 * <p>
 * Defaults are according to the JDBC standard; result set type will be
 * <code>ResultSet.TYPE_FORWARD_ONLY</code>, concurrency will be
 * <code>ResultSet.CONCUR_READ_ONLY</code> and the statement will not
 * return auto-generated keys.
 *
 * @param sql SQL query string
 * @param schema current compilation schema
 * @param holdability result set holdability
 * @return A statement key.
 */
public static StatementKey newPrepared(
        String sql, String schema, int holdability) {
    return new StatementKey(PREPARED, sql, schema,
            ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY,
            holdability, Statement.NO_GENERATED_KEYS);
}
 
源代码15 项目: spliceengine   文件: StatementKeyFactory.java
/**
 * Creates a key for a query with default settings.
 * <p>
 * Defaults are according to the JDBC standard; result set type will be
 * <code>ResultSet.TYPE_FORWARD_ONLY</code>, concurrency will be
 * <code>ResultSet.CONCUR_READ_ONLY</code> and the statement will not
 * return auto-generated keys.
 *
 * @param sql SQL query string
 * @param schema current compilation schema
 * @param holdability result set holdability
 * @return A statement key.
 */
public static StatementKey newPrepared(
        String sql, String schema, int holdability) {
    return new StatementKey(PREPARED, sql, schema,
            ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY,
            holdability, Statement.NO_GENERATED_KEYS);
}
 
源代码16 项目: gemfirexd-oss   文件: StatementKeyFactory.java
/**
 * Creates a key for a query specifying result set type and concurrency.
 * <p>
 * The returned key is for a statement not returning auto-generated keys.
 *
 * @param sql SQL query string
 * @param schema current compilation schema
 * @param rst result set type
 * @param rsc result set concurrency level
 * @param rsh result set holdability
 * @return A statement key.
 */
public static StatementKey newPrepared(
        String sql, String schema, int rst, int rsc, int rsh) {
    return new StatementKey(PREPARED, sql, schema, rst, rsc, rsh,
                            Statement.NO_GENERATED_KEYS);
}
 
源代码17 项目: gemfirexd-oss   文件: StatementKeyFactory.java
/**
 * Creates a key for a callable statement specifying result set type and
 * concurrency.
 * <p>
 * The returned key is for a statement not returning auto-generated keys.
 *
 * @param sql SQL query string
 * @param schema current compilation schema
 * @param rst result set type
 * @param rsc result set concurrency level
 * @param rsh result set holdability
 * @return A statement key.
 */
public static StatementKey newCallable(
        String sql, String schema, int rst, int rsc, int rsh) {
    return new StatementKey(CALLABLE, sql, schema, rst, rsc, rsh,
                            Statement.NO_GENERATED_KEYS);
}
 
源代码18 项目: spliceengine   文件: StatementKeyFactory.java
/**
 * Creates a key for a query specifying result set type and concurrency.
 * <p>
 * The returned key is for a statement not returning auto-generated keys.
 *
 * @param sql SQL query string
 * @param schema current compilation schema
 * @param rst result set type
 * @param rsc result set concurrency level
 * @param rsh result set holdability
 * @return A statement key.
 */
public static StatementKey newPrepared(
        String sql, String schema, int rst, int rsc, int rsh) {
    return new StatementKey(PREPARED, sql, schema, rst, rsc, rsh,
                            Statement.NO_GENERATED_KEYS);
}
 
源代码19 项目: gemfirexd-oss   文件: StatementKeyFactory.java
/**
 * Creates a key for a query specifying result set type and concurrency.
 * <p>
 * The returned key is for a statement not returning auto-generated keys.
 *
 * @param sql SQL query string
 * @param schema current compilation schema
 * @param rst result set type
 * @param rsc result set concurrency level
 * @param rsh result set holdability
 * @return A statement key.
 */
public static StatementKey newPrepared(
        String sql, String schema, int rst, int rsc, int rsh) {
    return new StatementKey(PREPARED, sql, schema, rst, rsc, rsh,
                            Statement.NO_GENERATED_KEYS);
}
 
源代码20 项目: spliceengine   文件: StatementKeyFactory.java
/**
 * Creates a key for a callable statement specifying result set type and
 * concurrency.
 * <p>
 * The returned key is for a statement not returning auto-generated keys.
 *
 * @param sql SQL query string
 * @param schema current compilation schema
 * @param rst result set type
 * @param rsc result set concurrency level
 * @param rsh result set holdability
 * @return A statement key.
 */
public static StatementKey newCallable(
        String sql, String schema, int rst, int rsc, int rsh) {
    return new StatementKey(CALLABLE, sql, schema, rst, rsc, rsh,
                            Statement.NO_GENERATED_KEYS);
}