Java Code Examples for java.sql.Statement#NO_GENERATED_KEYS
The following examples show how to use
java.sql.Statement#NO_GENERATED_KEYS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneratedKeysSupportFactory.java From jaybird with GNU Lesser General Public License v2.1 | 6 votes |
@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(); } }
Example 2
Source File: EmbedCallableStatement.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * @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(); }
Example 3
Source File: EmbedCallableStatement.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * @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(); }
Example 4
Source File: ExecuteAutoGeneratedKeys.java From sql-layer with GNU Affero General Public License v3.0 | 6 votes |
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); } }
Example 5
Source File: GeneratedKeysSupportFactory.java From jaybird with GNU Lesser General Public License v2.1 | 5 votes |
@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(); } }
Example 6
Source File: JdbcThinStatement.java From ignite with Apache License 2.0 | 5 votes |
/** {@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"); } }
Example 7
Source File: SnowflakeConnectionV1.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
@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(); }
Example 8
Source File: SnowflakeStatementV1.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
@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(); } }
Example 9
Source File: Results.java From mariadb-connector-j with GNU Lesser General Public License v2.1 | 5 votes |
/** * 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; }
Example 10
Source File: QueryUpdateOnSubscribe.java From rxjava-jdbc with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 11
Source File: JDBCStatement.java From evosql with Apache License 2.0 | 4 votes |
/** * <!-- 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(); }
Example 12
Source File: StatementKeyFactory.java From gemfirexd-oss with Apache License 2.0 | 3 votes |
/** * 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); }
Example 13
Source File: StatementKeyFactory.java From spliceengine with GNU Affero General Public License v3.0 | 3 votes |
/** * 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); }
Example 14
Source File: StatementKeyFactory.java From gemfirexd-oss with Apache License 2.0 | 3 votes |
/** * 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); }
Example 15
Source File: JDBCStatement.java From evosql with Apache License 2.0 | 3 votes |
/** * <!-- 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(); }
Example 16
Source File: StatementKeyFactory.java From gemfirexd-oss with Apache License 2.0 | 2 votes |
/** * 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); }
Example 17
Source File: StatementKeyFactory.java From spliceengine with GNU Affero General Public License v3.0 | 2 votes |
/** * 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); }
Example 18
Source File: StatementKeyFactory.java From spliceengine with GNU Affero General Public License v3.0 | 2 votes |
/** * 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); }
Example 19
Source File: StatementKeyFactory.java From gemfirexd-oss with Apache License 2.0 | 2 votes |
/** * 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); }
Example 20
Source File: StatementKeyFactory.java From gemfirexd-oss with Apache License 2.0 | 2 votes |
/** * 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); }