Top Description Fields Constructors Methods
org.h2.jdbc

public Class JdbcPreparedStatement

extends JdbcStatement
implements PreparedStatement
Class Inheritance
All Implemented Interfaces
java.sql.PreparedStatement, java.sql.Statement, java.lang.AutoCloseable, java.sql.Wrapper
Known Direct Subclasses
org.h2.jdbc.JdbcCallableStatement
Imports
java.io.InputStream, .Reader, java.math.BigDecimal, java.net.URL, java.sql.Array, .Blob, .Clob, .NClob, .ParameterMetaData, .PreparedStatement, .Ref, .ResultSet, .ResultSetMetaData, .RowId, .SQLException, .SQLType, .SQLXML, java.util.ArrayList, .Calendar, .HashMap, .Iterator, .List, org.h2.api.ErrorCode, org.h2.command.CommandInterface, org.h2.engine.Session, org.h2.expression.ParameterInterface, org.h2.message.DbException, .TraceObject, org.h2.result.BatchResult, .ResultInterface, .ResultWithGeneratedKeys, org.h2.util.IOUtils, .LegacyDateTimeUtils, .Utils, org.h2.value.DataType, .Value, .ValueBigint, .ValueBoolean, .ValueDouble, .ValueInteger, .ValueNull, .ValueNumeric, .ValueReal, .ValueSmallint, .ValueTinyint, .ValueToObjectConverter, .ValueVarbinary, .ValueVarchar

Represents a prepared statement.

Thread safety: the prepared statement is not thread-safe. If the same prepared statement is used by multiple threads access to it must be synchronized. The single synchronized block must include assignment of parameters, execution of the command and all operations with its result.

synchronized (prep) {
    prep.setInt(1, 10);
    try (ResultSet rs = prep.executeQuery()) {
        while (rs.next) {
            // Do something
        }
    }
}
synchronized (prep) {
    prep.setInt(1, 15);
    updateCount = prep.executeUpdate();
}

Field Summary

Modifier and TypeField and Description
private ArrayList<Value[]>
private HashMap<String, Integer>
protected CommandInterface
private final Object
Inherited from org.h2.jdbc.JdbcStatement:
connfetchSizegeneratedKeysmaxRowsresultSetresultSetConcurrencyresultSetTypesessionupdateCount

Constructor Summary

AccessConstructor and Description
pack-priv
JdbcPreparedStatement(JdbcConnection conn, String sql, int id, int resultSetType, int resultSetConcurrency, Object generatedKeysRequest)

Method Summary

Modifier and TypeMethod and Description
public void
addBatch(String
ignored
sql
)

Overrides org.h2.jdbc.JdbcStatement.addBatch.

Implements java.sql.Statement.addBatch.

Calling this method is not legal on a PreparedStatement.

public void
addBatch()

Implements java.sql.PreparedStatement.addBatch.

Adds the current settings to the batch.

public void
public void
clearParameters()

Implements java.sql.PreparedStatement.clearParameters.

Clears all parameters.

public void
close()

Overrides org.h2.jdbc.JdbcStatement.close.

Implements java.sql.Statement.close.

Closes this statement.

private SQLException
public boolean

Returns:

true if a result set is available, false if not
execute
()

Implements java.sql.PreparedStatement.execute.

Executes an arbitrary statement.

public int[]

Returns:

the array of update counts
executeBatch
()

Overrides org.h2.jdbc.JdbcStatement.executeBatch.

Implements java.sql.Statement.executeBatch.

Executes the batch.

private BatchResult
public long[]

Returns:

the array of update counts
executeLargeBatch
()

Overrides org.h2.jdbc.JdbcStatement.executeLargeBatch.

Overrides default java.sql.Statement.executeLargeBatch.

Executes the batch.

public long

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returns nothing)
executeLargeUpdate
()

Overrides default java.sql.PreparedStatement.executeLargeUpdate.

Executes a statement (insert, update, delete, create, drop) and returns the update count.

public ResultSet

Returns:

the result set
executeQuery
()

Implements java.sql.PreparedStatement.executeQuery.

Executes a query (select statement) and returns the result set.

public ResultSet
executeQuery(String
ignored
sql
)

Overrides org.h2.jdbc.JdbcStatement.executeQuery.

Implements java.sql.Statement.executeQuery.

Calling this method is not legal on a PreparedStatement.

public int

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returns nothing, or SUCCESS_NO_INFO if number of rows is too large for int data type)
executeUpdate
()

Implements java.sql.PreparedStatement.executeUpdate.

Executes a statement (insert, update, delete, create, drop) and returns the update count.

private long
public ResultSetMetaData

Returns:

the meta data or null if this is not a query
getMetaData
()

Implements java.sql.PreparedStatement.getMetaData.

Gets the result set metadata of the query returned when the statement is executed.

public ParameterMetaData

Returns:

the meta data
getParameterMetaData
()

Implements java.sql.PreparedStatement.getParameterMetaData.

Get the parameter meta data of this prepared statement.

public void
setArray(int
the parameter index (1, 2, ...)
parameterIndex
,
Array
the value
x
)

Implements java.sql.PreparedStatement.setArray.

Sets the value of a parameter as an Array.

public void
setAsciiStream(int
the parameter index (1, 2, ...)
parameterIndex
,
InputStream
the value
x
,
int
the maximum number of bytes
length
)

Implements java.sql.PreparedStatement.setAsciiStream.

Sets the value of a parameter as an ASCII stream.

public void
setAsciiStream(int
the parameter index (1, 2, ...)
parameterIndex
,
InputStream
the value
x
,
long
the maximum number of bytes
length
)

Implements java.sql.PreparedStatement.setAsciiStream.

Sets the value of a parameter as an ASCII stream.

public void
setAsciiStream(int
the parameter index (1, 2, ...)
parameterIndex
,
InputStream
the value
x
)

Implements java.sql.PreparedStatement.setAsciiStream.

Sets the value of a parameter as an ASCII stream.

public void
setBigDecimal(int
the parameter index (1, 2, ...)
parameterIndex
,
BigDecimal
the value
x
)

Implements java.sql.PreparedStatement.setBigDecimal.

Sets the value of a parameter.

public void
setBinaryStream(int
the parameter index (1, 2, ...)
parameterIndex
,
InputStream
the value
x
,
long
the maximum number of bytes
length
)

Implements java.sql.PreparedStatement.setBinaryStream.

Sets the value of a parameter as an input stream.

public void
setBinaryStream(int
the parameter index (1, 2, ...)
parameterIndex
,
InputStream
the value
x
,
int
the maximum number of bytes
length
)

Implements java.sql.PreparedStatement.setBinaryStream.

Sets the value of a parameter as an input stream.

public void
setBinaryStream(int
the parameter index (1, 2, ...)
parameterIndex
,
InputStream
the value
x
)

Implements java.sql.PreparedStatement.setBinaryStream.

Sets the value of a parameter as an input stream.

public void
setBlob(int
the parameter index (1, 2, ...)
parameterIndex
,
Blob
the value
x
)

Implements java.sql.PreparedStatement.setBlob.

Sets the value of a parameter as a Blob.

public void
setBlob(int
the parameter index (1, 2, ...)
parameterIndex
,
InputStream
the value
x
)

Implements java.sql.PreparedStatement.setBlob.

Sets the value of a parameter as a Blob.

public void
setBlob(int
the parameter index (1, 2, ...)
parameterIndex
,
InputStream
the value
x
,
long
the maximum number of bytes
length
)

Implements java.sql.PreparedStatement.setBlob.

Sets the value of a parameter as a Blob.

public void
setBoolean(int
the parameter index (1, 2, ...)
parameterIndex
,
boolean
the value
x
)

Implements java.sql.PreparedStatement.setBoolean.

Sets the value of a parameter.

public void
setByte(int
the parameter index (1, 2, ...)
parameterIndex
,
byte
the value
x
)

Implements java.sql.PreparedStatement.setByte.

Sets the value of a parameter.

public void
setBytes(int
the parameter index (1, 2, ...)
parameterIndex
,
byte[]
the value
x
)

Implements java.sql.PreparedStatement.setBytes.

Sets the value of a parameter as a byte array.

pack-priv void
setCachedColumnLabelMap(HashMap<String, Integer>
the column map
cachedColumnLabelMap
)

Cache the column labels (looking up the column index can sometimes show up on the performance profile).

public void
setCharacterStream(int
the parameter index (1, 2, ...)
parameterIndex
,
Reader
the value
x
,
int
the maximum number of characters
length
)

Implements java.sql.PreparedStatement.setCharacterStream.

Sets the value of a parameter as a character stream.

public void
setCharacterStream(int
the parameter index (1, 2, ...)
parameterIndex
,
Reader
the value
x
)

Implements java.sql.PreparedStatement.setCharacterStream.

Sets the value of a parameter as a character stream.

public void
setCharacterStream(int
the parameter index (1, 2, ...)
parameterIndex
,
Reader
the value
x
,
long
the maximum number of characters
length
)

Implements java.sql.PreparedStatement.setCharacterStream.

Sets the value of a parameter as a character stream.

public void
setClob(int
the parameter index (1, 2, ...)
parameterIndex
,
Clob
the value
x
)

Implements java.sql.PreparedStatement.setClob.

Sets the value of a parameter as a Clob.

public void
setClob(int
the parameter index (1, 2, ...)
parameterIndex
,
Reader
the value
x
)

Implements java.sql.PreparedStatement.setClob.

Sets the value of a parameter as a Clob.

public void
setClob(int
the parameter index (1, 2, ...)
parameterIndex
,
Reader
the value
x
,
long
the maximum number of characters
length
)

Implements java.sql.PreparedStatement.setClob.

Sets the value of a parameter as a Clob.

public void
setDate(int
the parameter index (1, 2, ...)
parameterIndex
,
Date
the value
x
)

Implements java.sql.PreparedStatement.setDate.

Sets the value of a parameter.

public void
setDate(int
the parameter index (1, 2, ...)
parameterIndex
,
Date
the value
x
,
Calendar
the calendar
calendar
)

Implements java.sql.PreparedStatement.setDate.

Sets the date using a specified time zone.

public void
setDouble(int
the parameter index (1, 2, ...)
parameterIndex
,
double
the value
x
)

Implements java.sql.PreparedStatement.setDouble.

Sets the value of a parameter.

public void
setFloat(int
the parameter index (1, 2, ...)
parameterIndex
,
float
the value
x
)

Implements java.sql.PreparedStatement.setFloat.

Sets the value of a parameter.

public void
setInt(int
the parameter index (1, 2, ...)
parameterIndex
,
int
the value
x
)

Implements java.sql.PreparedStatement.setInt.

Sets the value of a parameter.

public void
setLong(int
the parameter index (1, 2, ...)
parameterIndex
,
long
the value
x
)

Implements java.sql.PreparedStatement.setLong.

Sets the value of a parameter.

public void
setNCharacterStream(int
the parameter index (1, 2, ...)
parameterIndex
,
Reader
the value
x
,
long
the maximum number of characters
length
)

Implements java.sql.PreparedStatement.setNCharacterStream.

Sets the value of a parameter as a character stream.

public void
setNCharacterStream(int
the parameter index (1, 2, ...)
parameterIndex
,
Reader
the value
x
)

Implements java.sql.PreparedStatement.setNCharacterStream.

Sets the value of a parameter as a character stream.

public void
setNClob(int
the parameter index (1, 2, ...)
parameterIndex
,
NClob
the value
x
)

Implements java.sql.PreparedStatement.setNClob.

Sets the value of a parameter as a Clob.

public void
setNClob(int
the parameter index (1, 2, ...)
parameterIndex
,
Reader
the value
x
)

Implements java.sql.PreparedStatement.setNClob.

Sets the value of a parameter as a Clob.

public void
setNClob(int
the parameter index (1, 2, ...)
parameterIndex
,
Reader
the value
x
,
long
the maximum number of characters
length
)

Implements java.sql.PreparedStatement.setNClob.

Sets the value of a parameter as a Clob.

public void
setNString(int
the parameter index (1, 2, ...)
parameterIndex
,
String
the value
x
)

Implements java.sql.PreparedStatement.setNString.

Sets the value of a parameter.

public void
setNull(int
the parameter index (1, 2, ...)
parameterIndex
,
int
the data type (Types.x)
sqlType
)

Implements java.sql.PreparedStatement.setNull.

Sets a parameter to null.

public void
setNull(int
the parameter index (1, 2, ...)
parameterIndex
,
int
the data type (Types.x)
sqlType
,
String
this parameter is ignored
typeName
)

Implements java.sql.PreparedStatement.setNull.

Sets a parameter to null.

public void
setObject(int
the parameter index (1, 2, ...)
parameterIndex
,
Object
the value
x
)

Implements java.sql.PreparedStatement.setObject.

Sets the value of a parameter.

public void
setObject(int
the parameter index (1, 2, ...)
parameterIndex
,
Object
the value, null is allowed
x
,
int
the type as defined in java.sql.Types
targetSqlType
)

Implements java.sql.PreparedStatement.setObject.

Sets the value of a parameter.

public void
setObject(int
the parameter index (1, 2, ...)
parameterIndex
,
Object
the value, null is allowed
x
,
int
the type as defined in java.sql.Types
targetSqlType
,
int
is ignored
scale
)

Implements java.sql.PreparedStatement.setObject.

Sets the value of a parameter.

public void
setObject(int
the parameter index (1, 2, ...)
parameterIndex
,
Object
the value, null is allowed
x
,
SQLType
the SQL type
targetSqlType
)

Overrides default java.sql.PreparedStatement.setObject.

Sets the value of a parameter.

public void
setObject(int
the parameter index (1, 2, ...)
parameterIndex
,
Object
the value, null is allowed
x
,
SQLType
the SQL type
targetSqlType
,
int
is ignored
scaleOrLength
)

Overrides default java.sql.PreparedStatement.setObject.

Sets the value of a parameter.

private void
setObjectWithType(int parameterIndex, Object x, int type)

private void
setParameter(int parameterIndex, Value value)

public void
setRef(int
the first parameter is 1, the second is 2, ...
parameterIndex
,
Ref
an SQL REF value
x
)

Implements java.sql.PreparedStatement.setRef.

[Not supported] Sets the value of a column as a reference.

public void
setRowId(int
the first parameter is 1, the second is 2, ...
parameterIndex
,
RowId
the parameter value
x
)

Implements java.sql.PreparedStatement.setRowId.

[Not supported] Sets the value of a parameter as a row id.

public void
setShort(int
the parameter index (1, 2, ...)
parameterIndex
,
short
the value
x
)

Implements java.sql.PreparedStatement.setShort.

Sets the value of a parameter.

public void
setSQLXML(int
the parameter index (1, 2, ...)
parameterIndex
,
SQLXML
the value
x
)

Implements java.sql.PreparedStatement.setSQLXML.

Sets the value of a parameter as a SQLXML.

public void
setString(int
the parameter index (1, 2, ...)
parameterIndex
,
String
the value
x
)

Implements java.sql.PreparedStatement.setString.

Sets the value of a parameter.

public void
setTime(int
the parameter index (1, 2, ...)
parameterIndex
,
Time
the value
x
)

Implements java.sql.PreparedStatement.setTime.

Sets the value of a parameter.

public void
setTime(int
the parameter index (1, 2, ...)
parameterIndex
,
Time
the value
x
,
Calendar
the calendar
calendar
)

Implements java.sql.PreparedStatement.setTime.

Sets the time using a specified time zone.

public void
setTimestamp(int
the parameter index (1, 2, ...)
parameterIndex
,
Timestamp
the value
x
)

Implements java.sql.PreparedStatement.setTimestamp.

Sets the value of a parameter.

public void
setTimestamp(int
the parameter index (1, 2, ...)
parameterIndex
,
Timestamp
the value
x
,
Calendar
the calendar
calendar
)

Implements java.sql.PreparedStatement.setTimestamp.

Sets the timestamp using a specified time zone.

public void
setUnicodeStream(int
the first parameter is 1, the second is 2, ...
parameterIndex
,
InputStream
a java.io.InputStream object that contains the Unicode parameter value
x
,
int
the number of bytes in the stream
length
)

Implements java.sql.PreparedStatement.setUnicodeStream.

Deprecated since JDBC 2.0, use setCharacterStream

[Not supported] This feature is deprecated and not supported.

public void
setURL(int
the first parameter is 1, the second is 2, ...
parameterIndex
,
URL
the java.net.URL object to be set
x
)

Implements java.sql.PreparedStatement.setURL.

[Not supported]

public String
Inherited from org.h2.jdbc.JdbcStatement:
cancelcheckClosedclearWarningscloseIfCloseOnCompletioncloseOldResultSetcloseOnCompletionenquoteIdentifierexecuteexecuteexecuteexecuteexecuteLargeUpdateexecuteLargeUpdateexecuteLargeUpdateexecuteLargeUpdateexecuteUpdateexecuteUpdateexecuteUpdateexecuteUpdategetConnectiongetFetchDirectiongetFetchSizegetGeneratedKeysgetLargeMaxRowsgetLargeUpdateCountgetMaxFieldSizegetMaxRowsgetMoreResultsgetMoreResultsgetQueryTimeoutgetResultSetgetResultSetConcurrencygetResultSetHoldabilitygetResultSetTypegetUpdateCountgetWarningsisCancelledisClosedisCloseOnCompletionisPoolableisSimpleIdentifierisWrapperForonLazyResultSetClosesetCursorNamesetEscapeProcessingsetExecutingStatementsetFetchDirectionsetFetchSizesetLargeMaxRowssetMaxFieldSizesetMaxRowssetPoolablesetQueryTimeoutunwrap