Class DelayedPreparedStatement
PreparedStatement. It can be used to set variables before obtaining a
connection.
It also allows you to easily create a String containing the full statement with all the variable substituted, which can be useful for debugging purposes.
-
Constructor Summary
ConstructorsConstructorDescriptionDelayedPreparedStatement(SQLStatement sqlStatement) Constructs a newDelayedPreparedStatement. -
Method Summary
Modifier and TypeMethodDescriptionconstruct(Connection conn) Constructs aPreparedStatementfrom thisDelayedPreparedStatement, applying all variables as defined up to this point.construct(Connection conn, int autoGeneratedKeys) Constructs aPreparedStatementfrom thisDelayedPreparedStatement, applying all variables as defined up to this point.setBigDecimal(int idx, @Nullable BigDecimal obj) setBoolean(int idx, boolean obj) setByte(int idx, byte obj) setBytes(int idx, byte[] obj) setDouble(int idx, double obj) setFloat(int idx, float obj) setInt(int idx, int obj) setLong(int idx, long obj) setNextBigDecimal(@Nullable BigDecimal obj) setNextBoolean(boolean obj) setNextByte(byte obj) setNextBytes(byte[] obj) setNextDate(@Nullable Date obj) setNextDouble(double obj) setNextFloat(float obj) setNextInt(int obj) setNextLong(long obj) setNextNull(int sqlType) setNextObject(@Nullable Object obj, int targetSqlType) setNextRawString(String obj) Shortcut forsetRawString(int, String)with the current index.setNextShort(short obj) setNextString(@Nullable String obj) setNextTime(@Nullable Time obj) setNextTimestamp(@Nullable Timestamp obj) setNull(int idx, int sqlType) setRawString(int idx, String obj) Replaces a '?'setShort(int idx, short obj) setTimestamp(int idx, @Nullable Timestamp obj) toString()
-
Constructor Details
-
DelayedPreparedStatement
Constructs a newDelayedPreparedStatement.It counts the number of variables ('?' characters) in the statement.
- Parameters:
sqlStatement- The SQL statement.
-
-
Method Details
-
toString
-
construct
Constructs aPreparedStatementfrom thisDelayedPreparedStatement, applying all variables as defined up to this point.- Parameters:
conn- A connection to a database.- Returns:
- The constructed
PreparedStatement. - Throws:
SQLException- if a database access error occurs or this method is called on a closed connection.
-
construct
Constructs aPreparedStatementfrom thisDelayedPreparedStatement, applying all variables as defined up to this point.- Parameters:
conn- A connection to a database.autoGeneratedKeys- A flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS- Returns:
- The constructed
PreparedStatement. - Throws:
SQLException- if a database access error occurs or this method is called on a closed connection.
-
setNextRawString
Shortcut forsetRawString(int, String)with the current index.Read the documentation of
setRawString(int, String)to understand the implications of using this method.- Parameters:
obj- The name of the table.- Returns:
- This
DelayedPreparedStatement.
-
setRawString
Replaces a '?' at the given index with a raw String. Unlike all other types, this is executed before constructing the actualPreparedStatementand modifiesstatement.Note that you'll have to make sure that the String is sanitized and valid. For example, when using it to specify the name of a table, the name must comply with
IStorage.isValidTableName(String). This means that only alphanumerics characters and the underscore character are allowed.Most importantly: When using this method, it MUST BE USED in the correct order. Variables that should be set before should be added before and those that should be set after should be added after.
- Parameters:
idx- The index of the variable character (= "?") in the statement that should be replaced by the table name.obj- The name of the table.- Returns:
- This
DelayedPreparedStatement.
-
setNextBoolean
SeePreparedStatement.setBoolean(int, boolean).The index used is simply the one following from the previous set action.
- Parameters:
obj- The boolean to set.- Returns:
- This
DelayedPreparedStatement.
-
setBoolean
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The boolean to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextByte
SeePreparedStatement.setByte(int, byte).The index used is simply the one following from the previous set action.
- Parameters:
obj- The byte to set.- Returns:
- This
DelayedPreparedStatement.
-
setByte
- Returns:
- This
DelayedPreparedStatement.
-
setNextShort
SeePreparedStatement.setShort(int, short).The index used is simply the one following from the previous set action.
- Parameters:
obj- The short to set.- Returns:
- This
DelayedPreparedStatement.
-
setShort
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The short to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextInt
SeePreparedStatement.setInt(int, int).The index used is simply the one following from the previous set action.
- Parameters:
obj- The int to set.- Returns:
- This
DelayedPreparedStatement.
-
setInt
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The int to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextLong
SeePreparedStatement.setLong(int, long).The index used is simply the one following from the previous set action.
- Parameters:
obj- The long to set.- Returns:
- This
DelayedPreparedStatement.
-
setLong
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The long to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextFloat
SeePreparedStatement.setFloat(int, float).The index used is simply the one following from the previous set action.
- Parameters:
obj- The float to set.- Returns:
- This
DelayedPreparedStatement.
-
setFloat
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The float to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextDouble
SeePreparedStatement.setDouble(int, double).The index used is simply the one following from the previous set action.
- Parameters:
obj- The double to set.- Returns:
- This
DelayedPreparedStatement.
-
setDouble
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The double to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextBigDecimal
SeePreparedStatement.setBigDecimal(int, BigDecimal).The index used is simply the one following from the previous set action.
- Parameters:
obj- The BigDecimal to set.- Returns:
- This
DelayedPreparedStatement.
-
setBigDecimal
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The BigDecimal to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextString
SeePreparedStatement.setString(int, String).The index used is simply the one following from the previous set action.
- Parameters:
obj- The string to set.- Returns:
- This
DelayedPreparedStatement.
-
setString
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The string to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextBytes
SeePreparedStatement.setBytes(int, byte[]).The index used is simply the one following from the previous set action.
- Parameters:
obj- The bytes to set.- Returns:
- This
DelayedPreparedStatement.
-
setBytes
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The bytes to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextDate
SeePreparedStatement.setDate(int, Date).The index used is simply the one following from the previous set action.
- Parameters:
obj- The date to set.- Returns:
- This
DelayedPreparedStatement.
-
setDate
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The date to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextTime
SeePreparedStatement.setTime(int, Time).The index used is simply the one following from the previous set action.
- Parameters:
obj- The time to set.- Returns:
- This
DelayedPreparedStatement.
-
setTime
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The time to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextTimestamp
SeePreparedStatement.setTimestamp(int, Timestamp).The index used is simply the one following from the previous set action.
- Parameters:
obj- The timestamp to set.- Returns:
- This
DelayedPreparedStatement.
-
setTimestamp
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The timestamp to set.- Returns:
- This
DelayedPreparedStatement.
-
setNextObject
SeePreparedStatement.setObject(int, Object, int).The index used is simply the one following from the previous set action.
- Parameters:
obj- The object to set.targetSqlType- The SQL type to send to the database as defined inTypes.- Returns:
- This
DelayedPreparedStatement.
-
setObject
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...obj- The object to set.targetSqlType- The SQL type to send to the database as defined inTypes.- Returns:
- This
DelayedPreparedStatement.
-
setNextNull
SeePreparedStatement.setNull(int, int).The index used is simply the one following from the previous set action.
- Parameters:
sqlType- The SQL type to send to the database as defined inTypes.- Returns:
- This
DelayedPreparedStatement.
-
setNull
- Parameters:
idx- The parameter index. The first parameter is 1, the second is 2, ...sqlType- The SQL type to send to the database as defined inTypes.- Returns:
- This
DelayedPreparedStatement.
-