public class JdbcPreparedStatement extends JdbcStatement implements PreparedStatement
Thread safety: the prepared statement is not thread-safe. If the same prepared statement is used by multiple threads access to it must be synchronized. The single synchronized block must include assignment of parameters, execution of the command and all operations with its result.
synchronized (prep) {
prep.setInt(1, 10);
try (ResultSet rs = prep.executeQuery()) {
while (rs.next) {
// Do something
}
}
}
synchronized (prep) {
prep.setInt(1, 15);
updateCount = prep.executeUpdate();
}
| 限定符和类型 | 字段和说明 |
|---|---|
protected CommandInterface |
command |
conn, fetchSize, generatedKeys, maxRows, resultSet, resultSetConcurrency, resultSetType, session, updateCountARRAY, BLOB, CALLABLE_STATEMENT, CLOB, CONNECTION, DATA_SOURCE, DATABASE_META_DATA, PARAMETER_META_DATA, PREPARED_STATEMENT, RESULT_SET, RESULT_SET_META_DATA, SAVEPOINT, SQLXML, STATEMENT, trace, XA_DATA_SOURCE, XID| 限定符和类型 | 方法和说明 |
|---|---|
void |
addBatch()
Adds the current settings to the batch.
|
void |
addBatch(String sql)
Calling this method is not legal on a PreparedStatement.
|
void |
clearBatch()
Clears the batch.
|
void |
clearParameters()
Clears all parameters.
|
void |
close()
Closes this statement.
|
boolean |
execute()
Executes an arbitrary statement.
|
int[] |
executeBatch()
Executes the batch.
|
long[] |
executeLargeBatch()
Executes the batch.
|
long |
executeLargeUpdate()
Executes a statement (insert, update, delete, create, drop)
and returns the update count.
|
ResultSet |
executeQuery()
Executes a query (select statement) and returns the result set.
|
ResultSet |
executeQuery(String sql)
Calling this method is not legal on a PreparedStatement.
|
int |
executeUpdate()
Executes a statement (insert, update, delete, create, drop)
and returns the update count.
|
ResultSet |
getGeneratedKeys()
Return a result set with generated keys from the latest executed command
or an empty result set if keys were not generated or were not requested
with
Statement.RETURN_GENERATED_KEYS, column indexes, or column
names. |
ResultSetMetaData |
getMetaData()
Gets the result set metadata of the query returned when the statement is
executed.
|
ParameterMetaData |
getParameterMetaData()
Get the parameter meta data of this prepared statement.
|
void |
setArray(int parameterIndex,
Array x)
Sets the value of a parameter as an Array.
|
void |
setAsciiStream(int parameterIndex,
InputStream x)
Sets the value of a parameter as an ASCII stream.
|
void |
setAsciiStream(int parameterIndex,
InputStream x,
int length)
Sets the value of a parameter as an ASCII stream.
|
void |
setAsciiStream(int parameterIndex,
InputStream x,
long length)
Sets the value of a parameter as an ASCII stream.
|
void |
setBigDecimal(int parameterIndex,
BigDecimal x)
Sets the value of a parameter.
|
void |
setBinaryStream(int parameterIndex,
InputStream x)
Sets the value of a parameter as an input stream.
|
void |
setBinaryStream(int parameterIndex,
InputStream x,
int length)
Sets the value of a parameter as an input stream.
|
void |
setBinaryStream(int parameterIndex,
InputStream x,
long length)
Sets the value of a parameter as an input stream.
|
void |
setBlob(int parameterIndex,
Blob x)
Sets the value of a parameter as a Blob.
|
void |
setBlob(int parameterIndex,
InputStream x)
Sets the value of a parameter as a Blob.
|
void |
setBlob(int parameterIndex,
InputStream x,
long length)
Sets the value of a parameter as a Blob.
|
void |
setBoolean(int parameterIndex,
boolean x)
Sets the value of a parameter.
|
void |
setByte(int parameterIndex,
byte x)
Sets the value of a parameter.
|
void |
setBytes(int parameterIndex,
byte[] x)
Sets the value of a parameter as a byte array.
|
void |
setCharacterStream(int parameterIndex,
Reader x)
Sets the value of a parameter as a character stream.
|
void |
setCharacterStream(int parameterIndex,
Reader x,
int length)
Sets the value of a parameter as a character stream.
|
void |
setCharacterStream(int parameterIndex,
Reader x,
long length)
Sets the value of a parameter as a character stream.
|
void |
setClob(int parameterIndex,
Clob x)
Sets the value of a parameter as a Clob.
|
void |
setClob(int parameterIndex,
Reader x)
Sets the value of a parameter as a Clob.
|
void |
setClob(int parameterIndex,
Reader x,
long length)
Sets the value of a parameter as a Clob.
|
void |
setDate(int parameterIndex,
Date x)
Sets the value of a parameter.
|
void |
setDate(int parameterIndex,
Date x,
Calendar calendar)
Sets the date using a specified time zone.
|
void |
setDouble(int parameterIndex,
double x)
Sets the value of a parameter.
|
void |
setFloat(int parameterIndex,
float x)
Sets the value of a parameter.
|
void |
setInt(int parameterIndex,
int x)
Sets the value of a parameter.
|
void |
setLong(int parameterIndex,
long x)
Sets the value of a parameter.
|
void |
setNCharacterStream(int parameterIndex,
Reader x)
Sets the value of a parameter as a character stream.
|
void |
setNCharacterStream(int parameterIndex,
Reader x,
long length)
Sets the value of a parameter as a character stream.
|
void |
setNClob(int parameterIndex,
NClob x)
Sets the value of a parameter as a Clob.
|
void |
setNClob(int parameterIndex,
Reader x)
Sets the value of a parameter as a Clob.
|
void |
setNClob(int parameterIndex,
Reader x,
long length)
Sets the value of a parameter as a Clob.
|
void |
setNString(int parameterIndex,
String x)
Sets the value of a parameter.
|
void |
setNull(int parameterIndex,
int sqlType)
Sets a parameter to null.
|
void |
setNull(int parameterIndex,
int sqlType,
String typeName)
Sets a parameter to null.
|
void |
setObject(int parameterIndex,
Object x)
Sets the value of a parameter.
|
void |
setObject(int parameterIndex,
Object x,
int targetSqlType)
Sets the value of a parameter.
|
void |
setObject(int parameterIndex,
Object x,
int targetSqlType,
int scale)
Sets the value of a parameter.
|
void |
setObject(int parameterIndex,
Object x,
SQLType targetSqlType)
Sets the value of a parameter.
|
void |
setObject(int parameterIndex,
Object x,
SQLType targetSqlType,
int scaleOrLength)
Sets the value of a parameter.
|
void |
setRef(int parameterIndex,
Ref x)
[Not supported] Sets the value of a column as a reference.
|
void |
setRowId(int parameterIndex,
RowId x)
[Not supported] Sets the value of a parameter as a row id.
|
void |
setShort(int parameterIndex,
short x)
Sets the value of a parameter.
|
void |
setSQLXML(int parameterIndex,
SQLXML x)
Sets the value of a parameter as a SQLXML.
|
void |
setString(int parameterIndex,
String x)
Sets the value of a parameter.
|
void |
setTime(int parameterIndex,
Time x)
Sets the value of a parameter.
|
void |
setTime(int parameterIndex,
Time x,
Calendar calendar)
Sets the time using a specified time zone.
|
void |
setTimestamp(int parameterIndex,
Timestamp x)
Sets the value of a parameter.
|
void |
setTimestamp(int parameterIndex,
Timestamp x,
Calendar calendar)
Sets the timestamp using a specified time zone.
|
void |
setUnicodeStream(int parameterIndex,
InputStream x,
int length)
已过时。
since JDBC 2.0, use setCharacterStream
|
void |
setURL(int parameterIndex,
URL x)
[Not supported]
|
String |
toString()
INTERNAL
|
cancel, clearWarnings, closeOldResultSet, closeOnCompletion, enquoteIdentifier, execute, execute, execute, execute, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isCancelled, isClosed, isCloseOnCompletion, isPoolable, isSimpleIdentifier, isWrapperFor, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout, unwrapdebugCode, debugCodeAssign, debugCodeCall, debugCodeCall, debugCodeCall, getNextId, getTraceId, getTraceObjectName, isDebugEnabled, isInfoEnabled, logAndConvert, quote, quoteArray, quoteBigDecimal, quoteBytes, quoteDate, quoteIntArray, quoteMap, quoteTime, quoteTimestamp, setTrace, unsupportedclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcancel, clearWarnings, closeOnCompletion, execute, execute, execute, execute, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeoutisWrapperFor, unwrapprotected CommandInterface command
public ResultSet executeQuery() throws SQLException
executeQuery 在接口中 PreparedStatementSQLException - if this object is closed or invalidpublic int executeUpdate()
throws SQLException
executeUpdate 在接口中 PreparedStatementStatement.SUCCESS_NO_INFO if number of rows is too large for
int data type)SQLException - if this object is closed or invalidexecuteLargeUpdate()public long executeLargeUpdate()
throws SQLException
executeLargeUpdate 在接口中 PreparedStatementSQLException - if this object is closed or invalidpublic boolean execute()
throws SQLException
execute 在接口中 PreparedStatementSQLException - if this object is closed or invalidpublic void clearParameters()
throws SQLException
clearParameters 在接口中 PreparedStatementSQLException - if this object is closed or invalidpublic ResultSet executeQuery(String sql) throws SQLException
executeQuery 在接口中 StatementexecuteQuery 在类中 JdbcStatementsql - ignoredSQLException - Unsupported Featurepublic void addBatch(String sql) throws SQLException
addBatch 在接口中 StatementaddBatch 在类中 JdbcStatementsql - ignoredSQLException - Unsupported Featurepublic void setNull(int parameterIndex,
int sqlType)
throws SQLException
setNull 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)sqlType - the data type (Types.x)SQLException - if this object is closedpublic void setInt(int parameterIndex,
int x)
throws SQLException
setInt 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setString(int parameterIndex,
String x)
throws SQLException
setString 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setBigDecimal(int parameterIndex,
BigDecimal x)
throws SQLException
setBigDecimal 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setDate(int parameterIndex,
Date x)
throws SQLException
Usage of this method is discouraged. Use
setObject(parameterIndex, value) with LocalDate
parameter instead.
setDate 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedsetObject(int, Object)public void setTime(int parameterIndex,
Time x)
throws SQLException
Usage of this method is discouraged. Use
setObject(parameterIndex, value) with LocalTime
parameter instead.
setTime 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedsetObject(int, Object)public void setTimestamp(int parameterIndex,
Timestamp x)
throws SQLException
Usage of this method is discouraged. Use
setObject(parameterIndex, value) with
LocalDateTime parameter instead.
setTimestamp 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedsetObject(int, Object)public void setObject(int parameterIndex,
Object x)
throws SQLException
setObject 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setObject(int parameterIndex,
Object x,
int targetSqlType)
throws SQLException
setObject 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the value, null is allowedtargetSqlType - the type as defined in java.sql.TypesSQLException - if this object is closedpublic void setObject(int parameterIndex,
Object x,
int targetSqlType,
int scale)
throws SQLException
setObject 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the value, null is allowedtargetSqlType - the type as defined in java.sql.Typesscale - is ignoredSQLException - if this object is closedpublic void setObject(int parameterIndex,
Object x,
SQLType targetSqlType)
throws SQLException
setObject 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the value, null is allowedtargetSqlType - the SQL typeSQLException - if this object is closedpublic void setObject(int parameterIndex,
Object x,
SQLType targetSqlType,
int scaleOrLength)
throws SQLException
setObject 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the value, null is allowedtargetSqlType - the SQL typescaleOrLength - is ignoredSQLException - if this object is closedpublic void setBoolean(int parameterIndex,
boolean x)
throws SQLException
setBoolean 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setByte(int parameterIndex,
byte x)
throws SQLException
setByte 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setShort(int parameterIndex,
short x)
throws SQLException
setShort 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setLong(int parameterIndex,
long x)
throws SQLException
setLong 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setFloat(int parameterIndex,
float x)
throws SQLException
setFloat 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setDouble(int parameterIndex,
double x)
throws SQLException
setDouble 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setRef(int parameterIndex,
Ref x)
throws SQLException
setRef 在接口中 PreparedStatementSQLExceptionpublic void setDate(int parameterIndex,
Date x,
Calendar calendar)
throws SQLException
Usage of this method is discouraged. Use
setObject(parameterIndex, value) with LocalDate
parameter instead.
setDate 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuecalendar - the calendarSQLException - if this object is closedsetObject(int, Object)public void setTime(int parameterIndex,
Time x,
Calendar calendar)
throws SQLException
Usage of this method is discouraged. Use
setObject(parameterIndex, value) with LocalTime
parameter instead.
setTime 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuecalendar - the calendarSQLException - if this object is closedsetObject(int, Object)public void setTimestamp(int parameterIndex,
Timestamp x,
Calendar calendar)
throws SQLException
Usage of this method is discouraged. Use
setObject(parameterIndex, value) with
LocalDateTime parameter instead.
setTimestamp 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuecalendar - the calendarSQLException - if this object is closedsetObject(int, Object)@Deprecated public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException
setUnicodeStream 在接口中 PreparedStatementSQLExceptionpublic void setNull(int parameterIndex,
int sqlType,
String typeName)
throws SQLException
setNull 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)sqlType - the data type (Types.x)typeName - this parameter is ignoredSQLException - if this object is closedpublic void setBlob(int parameterIndex,
Blob x)
throws SQLException
setBlob 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setBlob(int parameterIndex,
InputStream x)
throws SQLException
setBlob 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setClob(int parameterIndex,
Clob x)
throws SQLException
setClob 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setClob(int parameterIndex,
Reader x)
throws SQLException
setClob 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setArray(int parameterIndex,
Array x)
throws SQLException
setArray 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setBytes(int parameterIndex,
byte[] x)
throws SQLException
setBytes 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setBinaryStream(int parameterIndex,
InputStream x,
long length)
throws SQLException
setBinaryStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuelength - the maximum number of bytesSQLException - if this object is closedpublic void setBinaryStream(int parameterIndex,
InputStream x,
int length)
throws SQLException
setBinaryStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuelength - the maximum number of bytesSQLException - if this object is closedpublic void setBinaryStream(int parameterIndex,
InputStream x)
throws SQLException
setBinaryStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setAsciiStream(int parameterIndex,
InputStream x,
int length)
throws SQLException
setAsciiStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuelength - the maximum number of bytesSQLException - if this object is closedpublic void setAsciiStream(int parameterIndex,
InputStream x,
long length)
throws SQLException
setAsciiStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuelength - the maximum number of bytesSQLException - if this object is closedpublic void setAsciiStream(int parameterIndex,
InputStream x)
throws SQLException
setAsciiStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setCharacterStream(int parameterIndex,
Reader x,
int length)
throws SQLException
setCharacterStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuelength - the maximum number of charactersSQLException - if this object is closedpublic void setCharacterStream(int parameterIndex,
Reader x)
throws SQLException
setCharacterStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setCharacterStream(int parameterIndex,
Reader x,
long length)
throws SQLException
setCharacterStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuelength - the maximum number of charactersSQLException - if this object is closedpublic void setURL(int parameterIndex,
URL x)
throws SQLException
setURL 在接口中 PreparedStatementSQLExceptionpublic ResultSetMetaData getMetaData() throws SQLException
getMetaData 在接口中 PreparedStatementSQLException - if this object is closedpublic void clearBatch()
throws SQLException
clearBatch 在接口中 StatementclearBatch 在类中 JdbcStatementSQLExceptionpublic void close()
throws SQLException
close 在接口中 AutoCloseableclose 在接口中 Statementclose 在类中 JdbcStatementSQLExceptionpublic int[] executeBatch()
throws SQLException
executeBatch 在接口中 StatementexecuteBatch 在类中 JdbcStatementSQLExceptionexecuteLargeBatch()public long[] executeLargeBatch()
throws SQLException
executeLargeBatch 在接口中 StatementexecuteLargeBatch 在类中 JdbcStatementSQLExceptionpublic ResultSet getGeneratedKeys() throws SQLException
JdbcStatementStatement.RETURN_GENERATED_KEYS, column indexes, or column
names.
Generated keys are only returned from from INSERT,
UPDATE, MERGE INTO, and MERGE INTO ... USING
commands.
If SQL command inserts or updates multiple rows with generated keys each such inserted or updated row is returned. Batch methods are also supported.
When Statement.RETURN_GENERATED_KEYS is used H2 chooses columns
to return automatically. The following columns are chosen:
IDENTITY columns and columns
with AUTO_INCREMENT.DEFAULT RANDOM_UUID()).Exact required columns for the returning result set may be specified on execution of command with names or indexes of columns.
getGeneratedKeys 在接口中 StatementgetGeneratedKeys 在类中 JdbcStatementSQLException - if this object is closedpublic void addBatch()
throws SQLException
addBatch 在接口中 PreparedStatementSQLExceptionpublic ParameterMetaData getParameterMetaData() throws SQLException
getParameterMetaData 在接口中 PreparedStatementSQLExceptionpublic void setRowId(int parameterIndex,
RowId x)
throws SQLException
setRowId 在接口中 PreparedStatementSQLExceptionpublic void setNString(int parameterIndex,
String x)
throws SQLException
setNString 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setNCharacterStream(int parameterIndex,
Reader x,
long length)
throws SQLException
setNCharacterStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuelength - the maximum number of charactersSQLException - if this object is closedpublic void setNCharacterStream(int parameterIndex,
Reader x)
throws SQLException
setNCharacterStream 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setNClob(int parameterIndex,
NClob x)
throws SQLException
setNClob 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setNClob(int parameterIndex,
Reader x)
throws SQLException
setNClob 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic void setClob(int parameterIndex,
Reader x,
long length)
throws SQLException
setClob 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuelength - the maximum number of charactersSQLException - if this object is closedpublic void setBlob(int parameterIndex,
InputStream x,
long length)
throws SQLException
setBlob 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuelength - the maximum number of bytesSQLException - if this object is closedpublic void setNClob(int parameterIndex,
Reader x,
long length)
throws SQLException
setNClob 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valuelength - the maximum number of charactersSQLException - if this object is closedpublic void setSQLXML(int parameterIndex,
SQLXML x)
throws SQLException
setSQLXML 在接口中 PreparedStatementparameterIndex - the parameter index (1, 2, ...)x - the valueSQLException - if this object is closedpublic String toString()
toString 在类中 JdbcStatementCopyright © 2022. All rights reserved.