Interface EnhancedPreparedStatement
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
EnhancedPreparedStatementBase,EnhancedPreparedStatementImpl
The definition of an enhanced
PreparedStatement.
The implementation of this interface wraps an instance of
PreparedStatement and provides solutions for three issues that the
original definition has:
- The placeholders in a prepared statement are only identified by their position, and it is quite easy to mix those positions up, especially when modifying the statement. This can cause errors during runtime that are very difficult to detect.
- The fact that the placeholders are only position based causes another
inconvenience. Assume an SQL statement like that one below:
where the question mark stands for the same value. This would require to callSELECT * FROM table1,table2 WHERE table1.key = table2.key AND table1.value < ? AND table2.value > ?setInt()twice, with the same value, but a different position index. PreparedStatementdoes not allow to log the SQL statement together with the assigned values for the placeholders; at least this is not defined in the interface itself; some vendor specific implementations may provide such an additional API, but there is no generic one. An implementation of this interface takes a method that can write any executed SQL statement to a logger.
- Note:
-
- The interface
EnhancedPreparedStatementdoes not extends the interfacejava.sql.PreparedStatement!
- The interface
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: EnhancedPreparedStatement.java 1091 2024-01-25 23:10:08Z tquadrat $
- Since:
- 0.1.0
- See Also:
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.sql.EnhancedPreparedStatement"
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceThe definition of logger method for aPreparedStatement. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe regular expression that is used to identify a named parameter in the SQL statement text: "[^:](:[a-zA-Z][a-zA-Z0-9]*)". -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBatch()Adds a set of parameters to thisEnhancedPreparedStatementinstance's batch of commands.voidcancel()Cancels thisEnhancedPreparedStatementobject if both the DBMS and driver support aborting an SQL statement.voidEmpties thisEnhancedPreparedStatementinstance's current list of SQL commands.voidClears the current parameter values immediately.voidClears all the warnings reported on thisEnhancedPreparedStatementinstance.voidclose()Releases this instance's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.voidSpecifies that thisEnhancedPreparedStatementwill be closed when all its dependent result sets are closed.static voidenableLogging(EnhancedPreparedStatement.StatementLogger logger, BooleanSupplier logCheck, boolean addStacktrace) Enables the logging output for theEnhancedPreparedStatementinstances.enquoteIdentifier(String identifier, boolean alwaysQuote) Returns a SQL identifier.enquoteLiteral(String value) Returns aStringenclosed in single quotes.Returns aStringrepresenting a National Character Set Literal enclosed in single quotes and prefixed with a upper case letterN.booleanexecute()Executes the SQL statement in thisPreparedStatementobject, which may be any kind of SQL statement.int[]Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.long[]Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.longExecutes the SQL statement in thisEnhancedPreparedStatementinstance.Executes the SQL query in thisPreparedStatementobject and returns theResultSetobject generated by the query.intExecutes the SQL statement in thisEnhancedPreparedStatementinstance.Retrieves theConnectioninstance that produced thePreparedStatementinstance wrapped by thisEnhancedPreparedStatement.intRetrieves the direction for fetching rows from database tables that is the default for result sets generated from thisEnhancedPreparedStatementinstance.intRetrieves the number of result set rows that is the default fetch size forResultSetinstances generated from thisEnhancedPreparedStatementinstance.Retrieves any auto-generated keys created as a result of executing thisEnhancedPreparedStatementinstance.longRetrieves the maximum number of rows that aResultSetinstance produced by thisEnhancedPreparedStatementinstance can contain.longRetrieves the current result as an update count.intRetrieves the maximum number of bytes that can be returned for character and binary column values in aResultSetobject produced by thisEnhancedPreparedStatementobject.intRetrieves the maximum number of rows that aResultSetinstance produced by thisEnhancedPreparedStatementinstance can contain.Retrieves aResultSetMetaDataobject that contains information about the columns of theResultSetinstance that will be returned when thisEnhancedPreparedStatementinstance is executed.booleanMoves to thisEnhancedPreparedStatementinstance's next result, returnstrueif it is aResultSetinstance, and implicitly closes any currentResultSetinstance(s) previously obtained with the methodgetResultSet().booleangetMoreResults(int current) Moves to thisEnhancedPreparedStatementinstance's next result, deals with any currentResultSetinstance(s) according to the instructions specified by the given flag, and returnstrueif the next result is aResultSetobject.Retrieves the number, types and properties of thisEnhancedPreparedStatementinstance's parameters.intRetrieves the number of seconds the driver will wait for aStatementinstance to execute.Retrieves the current result as aResultSetinstance.intRetrieves the result set concurrency forResultSetinstances generated by thisEnhancedPreparedStatementinstance.intRetrieves the result set holdability forResultSetinstances generated by thisEnhancedPreparedStatementinstance.intRetrieves the result set type forResultSetinstances generated by thisEnhancedPreparedStatementinstance.intRetrieves the current result as an update count.Retrieves the first warning reported by calls on thisEnhancedPreparedStatementinstance.booleanisClosed()Retrieves whether thisEnhancedPreparedStatementobject has been closed.booleanReturns a value indicating whether thisEnhancedPreparedStatementwill be closed when all its dependent result sets are closed.booleanChecks whether logging is currently enabled.booleanReturns a value indicating whether the wrappedPreparedStatementis poolable or not.booleanisSimpleIdentifier(String identifier) Retrieves whetheridentifieris a simple SQL identifier.static EnhancedPreparedStatementprepareStatement(Connection connection, String sql) Creates a newEnhancedPreparedStatementinstance.voidSets the designated parameter to the givenArrayinstance.voidsetAsciiStream(String parameterName, InputStream value) Sets the designated parameter to the givenInputStream.voidsetAsciiStream(String parameterName, InputStream value, int length) Sets the designated parameter to the givenInputStreamwhich will have the specified number of bytes.voidsetAsciiStream(String parameterName, InputStream value, long length) Sets the designated parameter to the givenInputStreamwhich will have the specified number of bytes.voidsetBigDecimal(String parameterName, BigDecimal value) Sets the designated parameter to the given JavaBigDecimalvalue.voidsetBinaryStream(String parameterName, InputStream value) Sets the designated parameter to the givenInputStream.voidsetBinaryStream(String parameterName, InputStream value, int length) Sets the designated parameter to the givenInputStreamwhich will have the specified number of bytes.voidsetBinaryStream(String parameterName, InputStream value, long length) Sets the designated parameter to the givenInputStreamwhich will have the specified number of bytes.voidsetBlob(String parameterName, InputStream value) Sets the designated parameter to aInputStreamobject.voidsetBlob(String parameterName, InputStream value, long length) Sets the designated parameter to aInputStreamobject.voidSets the designated parameter to the given JavaBlobinstance.voidsetBoolean(String parameterName, boolean value) Sets the designated parameter to the given Javabooleanvalue.voidSets the designated parameter to the given Javabytevalue.voidSets the designated parameter to the given Java array of bytes.voidsetCharacterStream(String parameterName, Reader value) Sets the designated parameter to the givenReaderinstance.voidsetCharacterStream(String parameterName, Reader value, int length) Sets the designated parameter to the givenReaderinstance, which provides the given number of characters.voidsetCharacterStream(String parameterName, Reader value, long length) Sets the designated parameter to the givenReaderinstance, which provides the given number of characters.voidSets the designated parameter to aReaderinstance.voidSets the designated parameter to aReaderinstance.voidSets the designated parameter to the givenClobinstance.voidsetCursorName(String name) Sets the SQL cursor name to the given String, which will be used by subsequent statementexecute()methods.voidSets the designated parameter to the givenDatevalue using the default time zone of the virtual machine that is running the application.voidvoidSets the designated parameter to the given Javadoublevalue.voidsetFetchDirection(int direction) Gives the driver a hint as to the direction in which rows will be processed inResultSetinstances created using thisEnhancedPreparedStatementobject.voidsetFetchSize(int rows) Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed forResultSetinstances generated by thisEnhancedPreparedStatementinstance.voidSets the designated parameter to the given Javafloatvalue.voidSets the designated parameter to the given Javaintvalue.voidsetLargeMaxRows(long max) Sets the limit for the maximum number of rows that anyResultSetinstance generated by thisEnhancedPreparedStatementinstance can contain.voidSets the designated parameter to the given Javalongvalue.voidsetMaxFieldSize(int max) Sets the limit for the maximum number of bytes that can be returned for character and binary column values in aResultSetobject produced by thisStatementobject.voidsetMaxRows(int max) Sets the limit for the maximum number of rows, that anyResultSetinstance generated by thisEnhancedPreparedStatementinstance can contain, to the given number.voidsetNCharacterStream(String parameterName, Reader value) Sets the designated parameter to the givenReaderinstance.voidsetNCharacterStream(String parameterName, Reader value, long length) Sets the designated parameter to the givenReaderinstance.voidSets the designated parameter to aReaderinstance.voidSets the designated parameter to aReaderinstance.voidSets the designated parameter to the givenNClobvalue.voidsetNString(String parameterName, String value) Sets the designated parameter to the given JavaStringvalue.voidSets the designated parameter to SQLNULL.voidSets the designated parameter to SQLNULL.voidSets the value of the designated parameter using the given object.voidSets the value of the designated parameter with the given object.voidSets the value of the designated parameter using the given object.voidsetQueryTimeout(int timeout) Sets the number of seconds the driver will wait for aStatementinstance to execute to the given number of seconds.voidSets the designated parameter to the givenREF(<structured-type>)value.voidSets the designated parameter to the givenRowIdinstance.voidSets the designated parameter to the given Javashortvalue.voidSets the designated parameter to the givenSQLXMLvalue.voidSets the designated parameter to the given JavaStringvalue.voidSets the designated parameter to the givenTimevalue.voidvoidsetTimestamp(String parameterName, Timestamp value) Sets the designated parameter to the givenTimestampvalue.voidsetTimestamp(String parameterName, Timestamp value, Calendar calendar) voidSets the designated parameter to the givenURLvalue.
-
Field Details
-
VARIABLE_PATTERN
The regular expression that is used to identify a named parameter in the SQL statement text: "[^:](:[a-zA-Z][a-zA-Z0-9]*)".- See Also:
-
-
Method Details
-
addBatch
Adds a set of parameters to thisEnhancedPreparedStatementinstance's batch of commands.- Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
cancel
Cancels this
EnhancedPreparedStatementobject if both the DBMS and driver support aborting an SQL statement.This method can be used by one thread to cancel a statement that is being executed by another thread.
- Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
clearBatch
Empties thisEnhancedPreparedStatementinstance's current list of SQL commands.- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatement, or the driver does not support batch updates.- See Also:
-
clearParameters
Clears the current parameter values immediately.
In general, parameter values remain in force for repeated use of a statement. Setting a parameter value automatically clears its previous value. However, in some cases it is useful to immediately release the resources used by the current parameter values; this can be done by calling the method
clearParameters().- Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
clearWarnings
Clears all the warnings reported on this
EnhancedPreparedStatementinstance. After a call to this method, the methodgetWarnings()will returnnulluntil a new warning is reported for thisEnhancedPreparedStatementinstance.- Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
close
Releases this instance's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources.
Calling the method
closeon aEnhancedPreparedStatementobject that is already closed has no effect.- Specified by:
closein interfaceAutoCloseable- Note:
-
- When a
EnhancedPreparedStatementinstance is closed, its currentResultSetinstance, if one exists, is also closed.
- When a
- Throws:
SQLException- A database access error occurred.
-
closeOnCompletion
Specifies that this
EnhancedPreparedStatementwill be closed when all its dependent result sets are closed. If the execution of theEnhancedPreparedStatementdoes not produce any result sets, this method has no effect.- Note:
-
- Multiple calls to
closeOnCompletion()do not toggle the effect on thisEnhancedPreparedStatement. However, a call tocloseOnCompletion()does affect both the subsequent execution of statements, and statements that currently have open, dependent, result sets.
- Multiple calls to
- Throws:
SQLException- This method was called on a closedEnhancedPreparedStatement.
-
enableLogging
static void enableLogging(EnhancedPreparedStatement.StatementLogger logger, BooleanSupplier logCheck, boolean addStacktrace) Enables the logging output for the
EnhancedPreparedStatementinstances.The
loggermethod takes three arguments:operation– The name of the operation that logs.statement– The source of the prepared statement.values– A list of the values in the format
A type of<name> [<type>]:<value>NULLindicates an unknown type; for large values (likeBloborReader) only the class is given instead of the real value.stacktrace– The stacktrace; will benullifaddStacktraceisfalse.
The
logCheckmethod returnstrueonly when logging should be done. No information is collected while it returnsfalse. As the method is called for nearly any operation, its implementation should be as efficient as possible.- Parameters:
logger- The method that takes the logging information.logCheck- The method that returns a flag whether log output is desired.addStacktrace-trueif the stacktrace should be added to the log output.
-
enquoteIdentifier
Returns a SQL identifier. If
identifieris a simple SQL identifier:- Return the original value if
alwaysQuoteisfalse - Return a delimited identifier if
alwaysQuoteistrue
If
identifieris not a simple SQL identifier,identifierwill be enclosed in double quotes if not already present. If the datasource does not support double quotes for delimited identifiers, the identifier should be enclosed by the string returned fromDatabaseMetaData.getIdentifierQuoteString(). If the datasource does not support delimited identifiers, aSQLFeatureNotSupportedExceptionshould be thrown.A
SQLExceptionwill be thrown ifidentifiercontains any characters invalid in a delimited identifier or the identifier length is invalid for the datasource.- Parameters:
identifier- An SQL identifier.alwaysQuote- Indicates if a simple SQL identifier should be returned as a quoted identifier.- Returns:
- A simple SQL identifier or a delimited identifier
- Throws:
SQLException- The identifier was not a valid identifier.SQLFeatureNotSupportedException- The datasource does not support delimited identifiers.NullPointerException- The identifier wasnull.
- Return the original value if
-
enquoteLiteral
Returns a
Stringenclosed in single quotes. Any occurrence of a single quote within the string will be replaced by two single quotes.Examples of the conversion: Value Result Hello 'Hello' G'Day 'G''Day' 'G''Day' '''G''''Day''' I'''M 'I''''''M' - Parameters:
value- A character String.- Returns:
- A string enclosed by single quotes with every single quote converted to two single quotes
- Throws:
NullPointerException- Thevalueargument wasnull.SQLException- A database access error occurred.
-
enquoteNCharLiteral
Returns a
Stringrepresenting a National Character Set Literal enclosed in single quotes and prefixed with a upper case letterN. Any occurrence of a single quote within the string will be replaced by two single quotes.Examples of the conversion: Value Result Hello N'Hello' G'Day N'G''Day' 'G''Day' N'''G''''Day''' I'''M N'I''''''M' N'Hello' N'N''Hello''' - Parameters:
s- A character string- Returns:
- The result of replacing every single quote character in the argument by two single quote characters where this entire result is then prefixed with 'N'.
- Throws:
SQLException- A database access error occurred.- See Also:
-
execute
Executes the SQL statement in this
PreparedStatementobject, which may be any kind of SQL statement.Some prepared statements return multiple results; the
execute()method handles these complex statements as well as the simpler form of statements handled by the methodsexecuteQuery()andexecuteUpdate().The
execute()method returns abooleanto indicate the form of the first result. You must call either the methodgetResultSet()orgetUpdateCount()to retrieve the result; you must callgetMoreResults()to move to any subsequent result(s).- Returns:
trueif the first result is aResultSetinstance;falseif the first result is an update count or there is no result.- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor no argument was supplied for at least one parameter.SQLTimeoutException- The driver determined that the timeout value that was specified by thesetQueryTimeout(int)method has been exceeded and has at least attempted to cancel the currently runningStatement.- See Also:
-
executeBatch
Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. The
intelements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch.The elements in the array returned by the method
executeBatch()may be one of the following:- A number greater than or equal to zero – indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution.
- A value of
Statement.SUCCESS_NO_INFO(-2 – indicates that the command was processed successfully but that the number of rows affected is unknown.
If one of the commands in a batch update fails to execute properly, this method throws a
BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch. However, the driver's behaviour must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands. If the driver continues processing after a failure, the array returned by the methodBatchUpdateException.getUpdateCounts()will contain as many elements as there are commands in the batch, and at least one of the elements will beStatement.EXECUTE_FAILED(-3 – indicating that the command failed to execute successfully); it occurs only if a driver continues to process commands after a command failed.- Note:
-
- The possible implementations and return values have been
modified in the Java 2 SDK, Standard Edition, version 1.3 to
accommodate the option of continuing to process commands in a batch
update after a
BatchUpdateExceptionobject has been thrown.
- The possible implementations and return values have been
modified in the Java 2 SDK, Standard Edition, version 1.3 to
accommodate the option of continuing to process commands in a batch
update after a
- Returns:
- An array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch.
- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the driver does not support batch statements.BatchUpdateException- One of the commands sent to the database failed to execute properly or attempts to return a result set.SQLTimeoutException- The driver determined that the timeout value that was specified by a call tosetQueryTimeout(int)was exceeded and at least attempted to cancel the currently running statement.- See Also:
-
executeLargeBatch
Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. The
intelements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch.The elements in the array returned by the method
executeBatch()may be one of the following:- A number greater than or equal to zero – indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution.
- A value of
Statement.SUCCESS_NO_INFO(-2 – indicates that the command was processed successfully but that the number of rows affected is unknown.
If one of the commands in a batch update fails to execute properly, this method throws a
BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch. However, the driver's behaviour must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands. If the driver continues processing after a failure, the array returned by the methodBatchUpdateException.getLargeUpdateCounts()will contain as many elements as there are commands in the batch, and at least one of the elements will beStatement.EXECUTE_FAILED(-3 – indicating that the command failed to execute successfully); it occurs only if a driver continues to process commands after a command failed.This method should be used when the returned row count may exceed
Integer.MAX_VALUE.- Returns:
- An array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch.
- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the driver does not support batch statements.BatchUpdateException- One of the commands sent to the database failed to execute properly or attempts to return a result set.SQLTimeoutException- The driver determined that the timeout value that was specified by a call tosetQueryTimeout(int)was exceeded and at least attempted to cancel the currently running statement.- See Also:
-
executeLargeUpdate
Executes the SQL statement in this
EnhancedPreparedStatementinstance. It must be an SQL Data Manipulation Language (DML) statement, such asINSERT,UPDATEorDELETE; or an SQL statement that returns nothing, such as a DDL statement.This method should be used when the returned row count may exceed
Integer.MAX_VALUE.The default implementation will throw
UnsupportedOperationException.- Returns:
- Either the row count for SQL Data Manipulation Language (DML) statements or 0 for SQL statements that return nothing.
- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the SQL statement returns aResultSetobject.SQLTimeoutException- The driver determined that the timeout value that was specified by thesetQueryTimeout(int)method has been exceeded and has at least attempted to cancel the currently runningStatement.
-
executeQuery
Executes the SQL query in this
PreparedStatementobject and returns theResultSetobject generated by the query.- Returns:
- A
ResultSetinstance that contains the data produced by the query; nevernull. - Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the SQL statement did not return aResultSetobject.SQLTimeoutException- The driver determined that the timeout value that was specified by thesetQueryTimeout(int)method has been exceeded and has at least attempted to cancel the currently runningStatement.
-
executeUpdate
Executes the SQL statement in this
EnhancedPreparedStatementinstance. It must be an SQL Data Manipulation Language (DML) statement, such asINSERT,UPDATEorDELETE; or an SQL statement that returns nothing, such as a DDL statement.- Returns:
- Either the row count for SQL Data Manipulation Language (DML) statements or 0 for SQL statements that return nothing.
- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the SQL statement returns aResultSetobject.SQLTimeoutException- The driver determined that the timeout value that was specified by thesetQueryTimeout(int)method has been exceeded and has at least attempted to cancel the currently runningStatement.
-
getConnection
Retrieves the
Connectioninstance that produced thePreparedStatementinstance wrapped by thisEnhancedPreparedStatement.- Returns:
- The connection that produced the wrapped prepared statement.
- Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
getFetchDirection
Retrieves the direction for fetching rows from database tables that is the default for result sets generated from this
EnhancedPreparedStatementinstance.If this
EnhancedPreparedStatementinstance has not set a fetch direction by calling the methodsetFetchDirection(int), the return value is implementation-specific.- Returns:
- The default fetch direction for result sets generated from this
EnhancedPreparedStatementinstance. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
getFetchSize
Retrieves the number of result set rows that is the default fetch size for
ResultSetinstances generated from thisEnhancedPreparedStatementinstance. If this statement instance has not set a fetch size by calling the methodsetFetchSize(int), the return value is implementation-specific.- Returns:
- The default fetch size for result sets generated from this
EnhancedPreparedStatementinstance. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
getGeneratedKeys
Retrieves any auto-generated keys created as a result of executing this
EnhancedPreparedStatementinstance. If this statement did not generate any keys, an emptyResultSetobject is returned.- Note:
-
- If the columns which represent the auto-generated keys were not specified, the JDBC driver implementation will determine the columns which best represent the auto-generated keys.
- Returns:
- A
ResultSetinstance containing the auto-generated key(s) generated by the execution of thisEnhancedPreparedStatementinstance. - Throws:
SQLException- A database access error occurred or this method was called on a closedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
getLargeMaxRows
Retrieves the maximum number of rows that a
ResultSetinstance produced by thisEnhancedPreparedStatementinstance can contain. If this limit is exceeded, the excess rows are silently dropped.This method should be used when the returned row limit may exceed
Integer.MAX_VALUE.The default implementation will return
0.- Returns:
- The current maximum number of rows for a
ResultSetinstance produced by thisEnhancedPreparedStatementinstance; zero means there is no limit, or that the method is not supported by the JDBC driver. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
getLargeUpdateCount
Retrieves the current result as an update count. If the result is a
ResultSetobject or there are no more results, -1 is returned.This method should be used when the returned row count may exceed
Integer.MAX_VALUE.The default implementation will throw
UnsupportedOperationException- Returns:
- The current result as an update count; -1 if the current result
is a
ResultSetobject or there are no more results. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
getMaxFieldSize
Retrieves the maximum number of bytes that can be returned for character and binary column values in a
ResultSetobject produced by thisEnhancedPreparedStatementobject.This limit applies only to
JDBCType.BINARY,JDBCType.VARBINARY,JDBCType.LONGVARBINARY,JDBCType.CHAR,JDBCType.VARCHAR,JDBCType.NCHAR,JDBCType.NVARCHAR,JDBCType.LONGNVARCHARandJDBCType.LONGVARCHARcolumns. If the limit is exceeded, the excess data is silently discarded.- Returns:
- The current column size limit for columns storing character and binary values; zero means there is no limit.
- Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement- See Also:
-
getMaxRows
Retrieves the maximum number of rows that a
ResultSetinstance produced by thisEnhancedPreparedStatementinstance can contain. If this limit is exceeded, the excess rows are silently dropped.- Returns:
- The current maximum number of rows for a
ResultSetinstance produced by thisEnhancedPreparedStatementinstance; zero means there is no limit. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
getMetaData
Retrieves a
ResultSetMetaDataobject that contains information about the columns of theResultSetinstance that will be returned when thisEnhancedPreparedStatementinstance is executed.Because the
PreparedStatementthat is wrapped by thisEnhancedPreparedStatementis precompiled, it is possible to know about theResultSetobject that it will return without having to execute it. Consequently, it is possible to invoke the methodgetMetaData()on aEnhancedPreparedStatementinstance rather than waiting to execute it and then invoking theResultSet.getMetaData()method on theResultSetinstance that is returned.- Note:
-
- Using this method may be expensive for some drivers due to the lack of underlying DBMS support.
- Returns:
- The description of a
ResultSetobject's columns ornullif the driver cannot return aResultSetMetaDataobject. - Throws:
SQLException- A database access error occurred or this method was called on a closedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
getMoreResults
Moves to this
EnhancedPreparedStatementinstance's next result, returnstrueif it is aResultSetinstance, and implicitly closes any currentResultSetinstance(s) previously obtained with the methodgetResultSet().There are no more results when the following is true:
// stmt is a EnhancedPreparedStatement object ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))- Returns:
trueif the next result is aResultSetinstance;falseif it is an update count or there are no more results.- Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
getMoreResults
Moves to this
EnhancedPreparedStatementinstance's next result, deals with any currentResultSetinstance(s) according to the instructions specified by the given flag, and returnstrueif the next result is aResultSetobject.There are no more results when the following is true:
// stmt is a Statement object ((stmt.getMoreResults( current ) == false) && (stmt.getUpdateCount() == -1))- Parameters:
current- One of the followingStatementconstants indicating what should happen to currentResultSetinstances obtained using the methodgetResultSet():Statement.CLOSE_CURRENT_RESULT,Statement.KEEP_CURRENT_RESULT, orStatement.CLOSE_ALL_RESULTS.- Returns:
trueif the next result is aResultSetinstance,falseif it is an update count or there are no more results- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the argument supplied is not one of the following:Statement.CLOSE_CURRENT_RESULT,Statement.KEEP_CURRENT_RESULT, orStatement.CLOSE_ALL_RESULTS.SQLFeatureNotSupportedException-DatabaseMetaData.supportsMultipleOpenResults()returnedfalseand eitherStatement.KEEP_CURRENT_RESULTorStatement.CLOSE_ALL_RESULTSare supplied as the argument.- See Also:
-
getParameterMetaData
Retrieves the number, types and properties of thisEnhancedPreparedStatementinstance's parameters.- Returns:
- An instance of
ParameterMetaDatathat contains information about the number, types and properties for each named parameter of thisEnhancedPreparedStatementinstance. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
getQueryTimeout
Retrieves the number of seconds the driver will wait for a
Statementinstance to execute. If the limit is exceeded, aSQLTimeoutExceptionis thrown.- Returns:
- The current query timeout limit in seconds; zero means there is no limit.
- Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
getResultSet
Retrieves the current result as a
ResultSetinstance.- Note:
-
- This method should be called only once per result.
- Returns:
- The current result as a
ResultSetinstance ornullif the result is an update count or there are no more results. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
getResultSetConcurrency
Retrieves the result set concurrency forResultSetinstances generated by thisEnhancedPreparedStatementinstance.- Returns:
- Either
ResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLE. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
getResultSetHoldability
Retrieves the result set holdability forResultSetinstances generated by thisEnhancedPreparedStatementinstance.- Returns:
- Either
ResultSet.HOLD_CURSORS_OVER_COMMIT(1) orResultSet.CLOSE_CURSORS_AT_COMMIT(2). - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
getResultSetType
Retrieves the result set type forResultSetinstances generated by thisEnhancedPreparedStatementinstance.- Returns:
- One of
ResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVE. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
getUpdateCount
Retrieves the current result as an update count. If the result is a
ResultSetobject or there are no more results, -1 is returned.- Note:
-
- This method should be called only once per result.
- Returns:
- The current result as an update count; -1 if the current result
is a
ResultSetobject or there are no more results. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
getWarnings
Retrieves the first warning reported by calls on this
.EnhancedPreparedStatementinstance. Subsequent warnings regarding the execution of this instance will be chained to thisSQLWarninginstanceThe warning chain is automatically cleared each time a statement is (re)executed. This method may not be called on a closed
EnhancedPreparedStatementinstance; doing so will cause anSQLExceptionto be thrown.- Note:
-
- If you are processing a
ResultSetinstance, any warnings associated with reads on thatResultSetinstance will be chained on it rather than on the statement instance that produced it.
- If you are processing a
- Returns:
- The first
SQLWarningobject ornullif there are no warnings. - Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.- See Also:
-
isClosed
Retrieves whether this
EnhancedPreparedStatementobject has been closed. AnEnhancedPreparedStatementis closed if the methodclose()has been called on it, or if it is automatically closed.- Returns:
trueif thisEnhancedPreparedStatementobject is closed;falseif it is still open.- Throws:
SQLException- A database access error occurred.
-
isCloseOnCompletion
Returns a value indicating whether this
EnhancedPreparedStatementwill be closed when all its dependent result sets are closed.- Returns:
trueif thisEnhancedPreparedStatementwill be closed when all of its dependent result sets are closed,falseotherwise.- Throws:
SQLException- This method was called on a closedEnhancedPreparedStatement.
-
isLoggingEnabled
boolean isLoggingEnabled()Checks whether logging is currently enabled.- Returns:
trueif logging is enabled and log information have to be collected,falseotherwise.
-
isPoolable
Returns a value indicating whether the wrappedPreparedStatementis poolable or not.- Returns:
trueif thePreparedStatementis poolable,falseotherwise- Throws:
SQLException- This method was called on a closedEnhancedPreparedStatement- See Also:
-
isSimpleIdentifier
Retrieves whetheridentifieris a simple SQL identifier.- Parameters:
identifier- An SQL identifier- Returns:
trueif the given value is a simple SQL identifier,falseotherwise- Throws:
SQLException- A database access error occurred.
-
prepareStatement
@API(status=STABLE, since="0.1.0") static EnhancedPreparedStatement prepareStatement(Connection connection, String sql) throws SQLException Creates a new
EnhancedPreparedStatementinstance.The text for the SQL statement is different from the format that is used by
Connection.prepareStatement(String)to create an instance ofPreparedStatement: this format uses explicit names instead of simple question marks as placeholders. This means, instead ofSELECT value FROM table WHERE key = ?one will write
SELECT value FROM table WHERE key = :keyThis allows to address the variables by name, and it makes it possible that the same value is only provided once, despite it occurs multiple time.
A parameter name is prefixed by a colon, followed by an ASCII letter, then by an arbitrary number of ASCII letters and digits. No special characters are allowed.
- Parameters:
connection- The connection to the database.sql- The text of the SQL statement with the placeholders.- Returns:
- The new statement.
- Throws:
SQLException- A database access error occurred, or the given statement could not be parsed properly.
-
setArray
Sets the designated parameter to the given
Arrayinstance.The driver converts this to an SQL
ARRAYvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method
-
setAsciiStream
Sets the designated parameter to the given
InputStreamwhich will have the specified number of bytes.When a very large ASCII value is input to a
LONGVARCHARparameter, it may be more practical to send it via ajava.io.InputStream. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from ASCII to the database char format.- Note:
-
- This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.length- The number of bytes in the stream.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setAsciiStream
Sets the designated parameter to the given
InputStreamwhich will have the specified number of bytes.When a very large ASCII value is input to a
LONGVARCHARparameter, it may be more practical to send it via ajava.io.InputStream. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from ASCII to the database char format.- Note:
-
- This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.length- The number of bytes in the stream.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setAsciiStream
Sets the designated parameter to the given
InputStream.When a very large ASCII value is input to a
LONGVARCHARparameter, it may be more practical to send it via ajava.io.InputStream. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from ASCII to the database char format.- Notes:
-
- This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Consult your JDBC driver documentation to determine if it might
be more efficient to use a version of
setAsciiStream()which takes a length parameter.
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setBinaryStream
Sets the designated parameter to the given
InputStreamwhich will have the specified number of bytes.When a very large binary value is input to a
LONGVARBINARYparameter, it may be more practical to send it via ajava.io.InputStream. The data will be read from the stream as needed until end-of-file is reached.- Note:
-
- This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.length- The number of bytes in the stream.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setBinaryStream
Sets the designated parameter to the given
InputStreamwhich will have the specified number of bytes.When a very large binary value is input to a
LONGVARBINARYparameter, it may be more practical to send it via ajava.io.InputStream. The data will be read from the stream as needed until end-of-file is reached.- Note:
-
- This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.length- The number of bytes in the stream.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setBinaryStream
Sets the designated parameter to the given
InputStream.When a very large binary value is input to a
LONGVARBINARYparameter, it may be more practical to send it via ajava.io.InputStream. The data will be read from the stream as needed until end-of-file is reached.- Notes:
-
- This stream object can either be a standard Java stream object or your own subclass that implements the standard interface.
- Consult your JDBC driver documentation to determine if it might
be more efficient to use a version of
setBinaryStream()which takes a length parameter.
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setBigDecimal
Sets the designated parameter to the given Java
BigDecimalvalue.The driver converts this to an SQL
NUMERICvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setBlob
Sets the designated parameter to the given Java
Blobinstance.The driver converts this to an SQL
BLOBvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setBlob
Sets the designated parameter to a
InputStreamobject. TheInputStreammust contain the number of characters as specified by thelengthargument, otherwise aSQLExceptionwill be generated when theEnhancedPreparedStatementis executed.This method differs from the
(String,InputStream,int)method because it informs the driver that the parameter value should be sent to the server as aBLOB. When thesetBinaryStream()method is used, the driver may have to do extra work to determine whether the parameter data should be sent to the server as aLONGVARBINARYor aBLOB.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- TheInputStreaminstance that contains the data to set the parameter value to.length- The number of bytes in the parameter data.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred, this method was called on a closedEnhancedPreparedStatement, the specified length was less than zero or if the number of bytes in theInputStreamdid not match the specified length.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setBlob
Sets the designated parameter to a
InputStreamobject.This method differs from the
(String,InputStream,int)method because it informs the driver that the parameter value should be sent to the server as aBLOB. When thesetBinaryStream()method is used, the driver may have to do extra work to determine whether the parameter data should be sent to the server as aLONGVARBINARYor aBLOB.- Note:
-
- Consult your JDBC driver documentation to determine if it might
be more efficient to use a version of
setBlob()which takes a length parameter.
- Consult your JDBC driver documentation to determine if it might
be more efficient to use a version of
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- TheInputStreaminstance that contains the data to set the parameter value to.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred, or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setBoolean
Sets the designated parameter to the given Java
booleanvalue.The driver converts this to an SQL
BITorBOOLEANvalue when it sends it to the database.For the logging, it is always
BOOLEAN.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setByte
Sets the designated parameter to the given Java
bytevalue.The driver converts this to an SQL
TINYINTvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setBytes
Sets the designated parameter to the given Java array of bytes.
The driver converts this to an SQL
VARBINARYorLONGVARBINARY(depending on the argument's size relative to the driver's limits onVARBINARYvalues) when it sends it to the database.For the logging, it is always
VARBINARY.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setCharacterStream
Sets the designated parameter to the given
Readerinstance, which provides the given number of characters.When a very large UNICODE value is input to a
LONGVARCHARparameter, it may be more practical to send it via ajava.io.Readerinstance. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from UNICODE to the database char format.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- Thejava.io.Readerobject that contains the Unicode data.length- The number of characters in the stream.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setCharacterStream
Sets the designated parameter to the given
Readerinstance, which provides the given number of characters.When a very large UNICODE value is input to a
LONGVARCHARparameter, it may be more practical to send it via ajava.io.Readerinstance. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from UNICODE to the database char format.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- Thejava.io.Readerobject that contains the Unicode data.length- The number of characters in the stream.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setCharacterStream
Sets the designated parameter to the given
Readerinstance.When a very large UNICODE value is input to a
LONGVARCHARparameter, it may be more practical to send it via ajava.io.Readerinstance. The data will be read from the stream as needed until end-of-file is reached. The JDBC driver will do any necessary conversion from UNICODE to the database char format.- Notes:
-
- This reader object can either be a standard Java
Readerobject or your own subclass that implements the standard interface. - Consult your JDBC driver documentation to determine if it might
be more efficient to use a version of
setCharacterStream()which takes a length parameter.
- This reader object can either be a standard Java
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- Thejava.io.Readerobject that contains the Unicode data.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setClob
Sets the designated parameter to the given
Clobinstance.The driver converts this to an SQL
CLOBvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method
-
setClob
Sets the designated parameter to a
Readerinstance. The reader must contain the number of characters specified by thelengthargument, otherwise aSQLExceptionwill be generated when theEnhancedPreparedStatementis executed.This method differs from the
setCharacterStream(String,Reader,int)method because it informs the driver that the parameter value should be sent to the server as aCLOB. When thesetCharacterStream()method is used, the driver may have to do extra work to determine whether the parameter data should be sent to the server as aLONGVARCHARor aCLOB.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- Thejava.io.Readerobject that contains the data to set the parameter value to.length- The number of characters in the stream.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement, theReaderwas shorter than specified, or the specified length was less than zero.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setClob
Sets the designated parameter to a
Readerinstance.This method differs from the
setCharacterStream(String,Reader,int)method because it informs the driver that the parameter value should be sent to the server as aCLOB. When thesetCharacterStream()method is used, the driver may have to do extra work to determine whether the parameter data should be sent to the server as aLONGVARCHARor aCLOB.- Note:
-
- Consult your JDBC driver documentation to determine if it might
be more efficient to use a version of
setClob()which takes a length parameter.
- Consult your JDBC driver documentation to determine if it might
be more efficient to use a version of
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- Thejava.io.Readerobject that contains the data to set the parameter value to.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setCursorName
Sets the SQL cursor name to the given String, which will be used by subsequent statement
execute()methods. This name can then be used in SQL positioned update or delete statements to identify the current row in theResultSetinstance generated by this statement. If the database does not support positioned update/delete, this method is a noop. To ensure that a cursor has the proper isolation level to support updates, the cursor'sSELECTstatement should have the formSELECT FOR UPDATE. IfFOR UPDATEis not present, positioned updates may fail.- Note:
-
- By definition, the execution of positioned updates and deletes
must be done by a different statement instances than the one that
generated the
ResultSetobject being used for positioning. Also, cursor names must be unique within a connection.
- By definition, the execution of positioned updates and deletes
must be done by a different statement instances than the one that
generated the
- Parameters:
name- The new cursor name, which must be unique within a connection.- Throws:
SQLException- A database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setDate
Sets the designated parameter to the given
Datevalue using the default time zone of the virtual machine that is running the application.The driver converts this to an SQL
DATEvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setDate
Sets the designated parameter to the given
Datevalue using the givenCalendarinstance. The driver used theCalendarinstance to construct an SQLDATEvalue, which the driver then sends to the database. With theCalendarinstance, the driver can calculate the date taking into account a custom timezone. If noCalendarinstance is specified, the driver uses the default timezone, which is that of the virtual machine running the application.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.calendar- TheCalendarinstance the driver will use to construct the date.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setDouble
Sets the designated parameter to the given Java
doublevalue.The driver converts this to an SQL
DOUBLEvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setFetchDirection
Gives the driver a hint as to the direction in which rows will be processed in
ResultSetinstances created using thisEnhancedPreparedStatementobject. The default value isResultSet.FETCH_FORWARD.Note that this method sets only the default fetch direction for result sets generated by this
EnhancedPreparedStatementinstance. Each result set has its own methods for getting and setting its own fetch direction.- Parameters:
direction- The initial direction for processing rows.- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the given direction is not one ofResultSet.FETCH_FORWARD,ResultSet.FETCH_REVERSE, orResultSet.FETCH_UNKNOWN- See Also:
-
setFetchSize
Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for
ResultSetinstances generated by thisEnhancedPreparedStatementinstance. If the specified value is zero, then the hint is ignored.The default value is zero.
- Parameters:
rows- The number of rows to fetch.- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the conditionrows >= 0was not satisfied.
-
setFloat
Sets the designated parameter to the given Java
floatvalue.The driver converts this to an SQL
REALvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setInt
Sets the designated parameter to the given Java
intvalue.The driver converts this to an SQL
INTEGERvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setLargeMaxRows
Sets the limit for the maximum number of rows that any
ResultSetinstance generated by thisEnhancedPreparedStatementinstance can contain. If the limit is exceeded, the excess rows are silently dropped.This method should be used when the row limit may exceed
Integer.MAX_VALUE.The default implementation will throw
UnsupportedOperationException.- Parameters:
max- The new max rows limit; zero means there is no limit.- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the conditionmax >= 0is not satisfied.- See Also:
-
setLong
Sets the designated parameter to the given Java
longvalue.The driver converts this to an SQL
BIGINTvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setMaxFieldSize
Sets the limit for the maximum number of bytes that can be returned for character and binary column values in a
ResultSetobject produced by thisStatementobject.This limit applies only to
JDBCType.BINARY,JDBCType.VARBINARY,JDBCType.LONGVARBINARY,JDBCType.CHAR,JDBCType.VARCHAR,JDBCType.NCHAR,JDBCType.NVARCHAR,JDBCType.LONGNVARCHARandJDBCType.LONGVARCHARcolumns. If the limit is exceeded, the excess data is silently discarded. For maximum portability, use values greater than 256.- Parameters:
max- The new column size limit in bytes; zero means there is no limit.- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the conditionmax >= 0is not satisfied.- See Also:
-
setMaxRows
Sets the limit for the maximum number of rows, that any
ResultSetinstance generated by thisEnhancedPreparedStatementinstance can contain, to the given number. If the limit is exceeded, the excess rows are silently dropped.- Parameters:
max- The new max rows limit; zero means there is no limit.- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the conditionmax >= 0was not satisfied.- See Also:
-
setNCharacterStream
Sets the designated parameter to the given
Readerinstance.The
Readerreads the data till end-of-file is reached. The driver does the necessary conversion from Java character format to the national character set in the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- Thejava.io.Readerobject that contains the data.length- The number of characters in the stream.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, the driver does not support national character sets, the driver detected that a data conversion error could occur, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method,
-
setNCharacterStream
Sets the designated parameter to the given
Readerinstance.The
Readerreads the data till end-of-file is reached. The driver does the necessary conversion from Java character format to the national character set in the database.- Notes:
-
- This reader object can either be a standard Java
Readerobject or your own subclass that implements the standard interface. - Consult your JDBC driver documentation to determine if it might
be more efficient to use a version of
setNCharacterStream()which takes a length parameter.
- This reader object can either be a standard Java
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- Thejava.io.Readerobject that contains the data.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, the driver does not support national character sets, the driver detected that a data conversion error could occur, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method,
-
setNClob
Sets the designated parameter to the given
NClobvalue.The driver converts this to an SQL
NCLOBvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, the driver does not support national character sets, the driver detected that a data conversion error could occur, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method,
-
setNClob
Sets the designated parameter to a
Readerinstance. The reader must contain the number of characters specified by thelengthargument, otherwise aSQLExceptionwill be generated when theEnhancedPreparedStatementis executed.This method differs from the
setNCharacterStream(String,Reader,long)method because it informs the driver that the parameter value should be sent to the server as aNCLOB. When thesetNCharacterStream()method is used, the driver may have to do extra work to determine whether the parameter data should be sent to the server as aLONGNVARCHARor aNCLOB.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- Thejava.io.Readerobject that contains the data to set the parameter value to.length- The number of characters in the stream.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement, theReaderwas shorter than specified, or the specified length was less than zero.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setNClob
Sets the designated parameter to a
Readerinstance.This method differs from the
setNCharacterStream(String,Reader,long)method because it informs the driver that the parameter value should be sent to the server as aNCLOB. When thesetNCharacterStream()method is used, the driver may have to do extra work to determine whether the parameter data should be sent to the server as aLONGNVARCHARor aNCLOB.- Note:
-
- Consult your JDBC driver documentation to determine if it might
be more efficient to use a version of
setNClob()which takes a length parameter.
- Consult your JDBC driver documentation to determine if it might
be more efficient to use a version of
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- Thejava.io.Readerobject that contains the data to set the parameter value to.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setNString
Sets the designated parameter to the given Java
Stringvalue.The driver converts this to an SQL
NCHAR,NVARCHAR, orLONGNVARCHARvalue (depending on the argument's size relative to the driver's limits onNVARCHARvalues)when it sends it to the database.For the logging, it is always
NCHAR.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, the driver does not support national character sets, the driver detected that a data conversion error could occur, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setNull
Sets the designated parameter to SQLNULL.- Note:
-
- You must specify the parameter's SQL type.
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.sqlType- The SQL type code.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- ThesqlTypeis aJDBCType.ARRAY,JDBCType.BLOB,JDBCType.CLOB,JDBCType.DATALINK,JDBCType.JAVA_OBJECT,JDBCType.NCHAR,JDBCType.NCLOB,JDBCType.NVARCHAR,JDBCType.LONGNVARCHAR,JDBCType.REF,JDBCType.ROWID,JDBCType.SQLXMLorJDBCType.STRUCTdata type and the JDBC driver does not support this data type.- See Also:
-
setNull
Sets the designated parameter to SQL
NULL.This version of the method
setNull()should be used for user-defined types and REF type parameters. Examples of user-defined types include:STRUCT,DISTINCT,JAVA_OBJECT, and named array types.Although this method is intended for user-defined and
REFparameters, this method may be used to set anullparameter of any JDBC type. If the parameter does not have a user-defined orREFtype, the giventypeNameis ignored.- Note:
-
- To be portable, applications must give the SQL type code and
the fully-qualified SQL type name when specifying a
NULLuser-defined orREFparameter. In the case of a user-defined type the name is the type name of the parameter itself. For aREFparameter, the name is the type name of the referenced type. If a JDBC driver does not need the type code or type name information, it may ignore it.
- To be portable, applications must give the SQL type code and
the fully-qualified SQL type name when specifying a
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.sqlType- The SQL type code.typeName- The fully-qualified name of an SQL user-defined type; ignored if the parameter is not a user-defined type orREF.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- ThesqlTypeis aJDBCType.ARRAY,JDBCType.BLOB,JDBCType.CLOB,JDBCType.DATALINK,JDBCType.JAVA_OBJECT,JDBCType.NCHAR,JDBCType.NCLOB,JDBCType.NVARCHAR,JDBCType.LONGNVARCHAR,JDBCType.REF,JDBCType.ROWID,JDBCType.SQLXMLorJDBCType.STRUCTdata type and the JDBC driver does not support this data type.
-
setObject
Sets the value of the designated parameter using the given object.
The JDBC specification specifies a standard mapping from Java
Objecttypes to SQL types. The given argument will be converted to the corresponding SQL type before being sent to the database.Note that this method may be used to pass database- specific abstract data types, by using a driver-specific Java type.
If the object is of a class implementing the interface
SQLData, the JDBC driver should call the methodSQLData.writeSQLto write it to the SQL data stream.If, on the other hand, the object is of a class implementing
Ref,Blob,Clob,NClob,Struct,URL,RowId,SQLXMLorArray, the driver should pass it to the database as a value of the corresponding SQL type.- Notes:
-
- Not all databases allow for a non-typed
NULLto be sent to the backend. For maximum portability, thesetNull()or thesetObject( final String parameterName, final Object x, int sqlType )method should be used instead ofsetObject( final String parameterName, final Object value )withvalueset tonull - This method throws an exception if there is an ambiguity, for example, if the object is of a class implementing more than one of the interfaces named above.
- Not all databases allow for a non-typed
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The object containing the input parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred, this method was called on a closedEnhancedPreparedStatementor the type of the given object is ambiguous.
-
setObject
void setObject(String parameterName, Object value, SQLType targetSqlType, int scaleOrLength) throws SQLException Sets the value of the designated parameter using the given object.
If the second argument is an
.InputStreamor aReaderthen the stream must contain the number of bytes specified by thescaleOrLengthargumentIf these conditions are not true the driver will generate a
SQLExceptionwhen the prepared statement is executed.The given Java object will be converted to the given
targetSqlTypebefore being sent to the database.If the object has a custom mapping (is of a class implementing the interface
SQLData), the JDBC driver should call the methodSQLData.writeSQL(SQLOutput)to write it to the SQL data stream.If, on the other hand, the object is of a class implementing
Ref,Blob,Clob,NClob,Struct,URL, orArray, the driver should pass it to the database as a value of the corresponding SQL type.Note that this method may be used to pass database-specific abstract data types.
- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The object containing the input parameter value.targetSqlType- The SQL type to be sent to the database. The scale argument may further qualify this type.scaleOrLength- ForJDBCType.DECIMALorJDBCType.NUMERICtypes, this is the number of digits after the decimal point. For Java Object typesInputStreamandReader, this is the length of the data in the stream or reader. For all other types, this value will be ignored.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred, this method was called on a closedEnhancedPreparedStatementor the Java Object specified byvalueis anInputStreamorReaderinstance and the value of the scale parameter is less than zero.SQLFeatureNotSupportedException- The JDBC driver does not support the specifiedtargetSqlType.- See Also:
-
setObject
Sets the value of the designated parameter with the given object.
This method is similar to
setObject(String,Object,SQLType,int), except that it assumes a scale of zero.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The object containing the input parameter value.targetSqlType- The SQL type to be sent to the database. The scale argument may further qualify this type.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred, or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support the specifiedtargetSqlType.- See Also:
-
setQueryTimeout
Sets the number of seconds the driver will wait for a
Statementinstance to execute to the given number of seconds. By default there is no limit on the amount of time allowed for a running statement to complete.If the limit is exceeded, an
SQLTimeoutExceptionis thrown.A JDBC driver must apply this limit to the
Statement.execute(String),Statement.executeQuery(String)andStatement.executeUpdate(String)methods.- Notes:
-
- JDBC driver implementations may also apply this limit to
ResultSetmethods (consult your driver vendor documentation for details). - In the case of
Statementbatching, it is implementation defined whether the time-out is applied to individual SQL commands added via the#addBatch()method or to the entire batch of SQL commands invoked by theexecuteBatch()method (consult your driver vendor documentation for details).
- JDBC driver implementations may also apply this limit to
- Parameters:
timeout- The new query timeout limit in seconds; zero means there is no limit- Throws:
SQLException- A database access error occurred, this method was called on a closedEnhancedPreparedStatementor the conditionseconds >= 0is not satisfied- See Also:
-
setRef
Sets the designated parameter to the given
REF(<structured-type>)value.The driver converts this to an SQL
REFvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setRowId
Sets the designated parameter to the given
RowIdinstance.The driver converts this to an SQL
ROWIDvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setShort
Sets the designated parameter to the given Java
shortvalue.The driver converts this to an SQL
SMALLINTvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setSQLXML
Sets the designated parameter to the given
SQLXMLvalue.The driver converts this to an SQL
SQLXMLvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- AnSQLXMLinstance that maps an SQLSQLXMLvalue.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred, this method was called on a closedEnhancedPreparedStatement, or theResult,WriterorOutputStreamwas closed for theSQLXMLobject.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
setString
Sets the designated parameter to the given Java
Stringvalue.The driver converts this to an SQL
VARCHARorLONGVARCHARvalue (depending on the argument's size relative to the driver's limits onVARCHARvalues) when it sends it to the database.For the logging, it is always
VARCHAR.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setTime
Sets the designated parameter to the given
Timevalue.The driver converts this to an SQL
TIMEvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setTime
Sets the designated parameter to the given
Timevalue using the givenCalendarinstance. The driver used theCalendarinstance to construct an SQLTIMEvalue, which the driver then sends to the database. With theCalendarinstance, the driver can calculate the date taking into account a custom timezone. If noCalendarinstance is specified, the driver uses the default timezone, which is that of the virtual machine running the application.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.calendar- TheCalendarinstance the driver will use to construct the date.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setTimestamp
Sets the designated parameter to the given
Timestampvalue.The driver converts this to an SQL
TIMESTAMPvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setTimestamp
Sets the designated parameter to the given
Timestampvalue using the givenCalendarinstance. The driver used theCalendarinstance to construct an SQLTIMESTAMPvalue, which the driver then sends to the database. With theCalendarinstance, the driver can calculate the timestamp taking into account a custom timezone. If noCalendarinstance is specified, the driver uses the default timezone, which is that of the virtual machine running the application.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.calendar- TheCalendarinstance the driver will use to construct the date.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.
-
setURL
Sets the designated parameter to the given
URLvalue.The driver converts this to an SQL
DATALINKvalue when it sends it to the database.- Parameters:
parameterName- The name of the parameter, prefixed by a colon.value- The parameter value.- Throws:
SQLException- The parameter name did not correspond to any defined parameter in the SQL statement, a database access error occurred or this method was called on a closedEnhancedPreparedStatement.SQLFeatureNotSupportedException- The JDBC driver does not support this method.
-
