Top Inners Fields Constructors Methods
org.postgresql.jdbc

public Class PgStatement

extends Object
implements Statement, BaseStatement
Class Inheritance
All Implemented Interfaces
org.postgresql.core.BaseStatement, java.sql.Statement, java.lang.AutoCloseable, java.sql.Wrapper, org.postgresql.PGStatement
Known Direct Subclasses
org.postgresql.jdbc.PgPreparedStatement
Static Imports
org.postgresql.util.internal.Nullness.castNonNull

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
PgStatement.StatementResultHandler

ResultHandler implementations for updates, queries, and either-or.

Field Summary

Modifier and TypeField and Description
protected boolean
protected @Nullable ArrayList<@Nullable ParameterList>
protected @Nullable ArrayList<Query>
private static final AtomicReferenceFieldUpdater<PgStatement, @Nullable TimerTask>
private volatile @Nullable TimerTask
cancelTimerTask

Protects current statement from cancelTask starting, waiting for a bit, and waking up exactly on subsequent query execution.

private boolean
protected final int
protected final PgConnection
private static final boolean
DEFAULT_FORCE_BINARY_TRANSFERS

Default state for use or not binary transfers.

protected int
protected int
fetchSize

Number of rows to get in a batch.

protected org.postgresql.jdbc.@org.checkerframework.checker.nullness.qual.Nullable,@org.checkerframework.checker.lock.qual.GuardedBy({"<self>"}) ResultWrapper
firstUnclosedResult

The first unclosed result.

private boolean
protected @Nullable ResultWrapper
generatedKeys

Results returned by a statement that wants generated keys.

private static final AtomicIntegerFieldUpdater<PgStatement>
private volatile int
protected final ResourceLock
protected int
protected int
maxrows

Maximum number of rows to return, 0 = unlimited.

protected int
private static final String[]
private boolean
protected boolean
protected @Nullable ResultWrapper
result

The current results.

protected final int
private final int
private static final AtomicReferenceFieldUpdater<PgStatement, StatementCancelState>
private volatile StatementCancelState
statementState

Protects statement from out-of-order cancels.

protected long
timeout

Timeout (in milliseconds) for a query.

private @Nullable TimestampUtils
public boolean
wantsGeneratedKeysAlways

Was this PreparedStatement created to return generated keys for every execution?

protected boolean
wantsGeneratedKeysOnce

Does the caller of execute/executeUpdate want generated keys for this execution?

protected volatile @Nullable PSQLWarningWrapper
warnings

The warnings chain.

Constructor Summary

AccessConstructor and Description
pack-priv
PgStatement(PgConnection c, int rsType, int rsConcurrency, int rsHoldability)

Method Summary

Modifier and TypeMethod and Description
public void
addBatch(String
typically this is a SQL INSERT or UPDATE statement
sql
)

Implements java.sql.Statement.addBatch.

Adds the given SQL command to the current list of commands for this Statement object.

public void
addWarning(SQLWarning
warning to add
warn
)

Either initializes new warning wrapper, or adds warning onto the chain.

public void
cancel()

Implements java.sql.Statement.cancel.

Cancels this Statement object if both the DBMS and driver support aborting an SQL statement.

pack-priv void
protected void
protected void
protected final void
private boolean
cleanupTimer()

Clears cancelTimerTask if any.

public void
clearBatch()

Implements java.sql.Statement.clearBatch.

Empties this Statement object's current list of SQL commands.

public void
clearWarnings()

Implements java.sql.Statement.clearWarnings.

Clears the warning chain.

public final void
close()

Implements java.sql.Statement.close.

Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.

protected void
protected void
closeImpl()

This is guaranteed to be called exactly once even in case of concurrent close() calls.

public void
closeOnCompletion()

Implements java.sql.Statement.closeOnCompletion.

Specifies that this Statement will be closed when all its dependent result sets are closed.

private void
protected BatchResultHandler
createBatchHandler(Query[] queries, @Nullable ParameterList[] parameterLists)

public ResultSet
createDriverResultSet(Field[]
the column metadata for the resultset
fields
,
List<Tuple>
the resultset data
tuples
)

Implements org.postgresql.core.BaseStatement.createDriverResultSet.

Create a synthetic resultset from data provided by the driver.

public ResultSet
createResultSet(@Nullable Query
the query that generated this resultset; used when dealing with updateable resultsets
originalQuery
,
Field[]
the column metadata for the resultset
fields
,
List<Tuple>
the resultset data
tuples
,
@Nullable ResultCursor
the cursor to use to retrieve more data from the server; if null, no additional data is present.
cursor
)

Implements org.postgresql.core.BaseStatement.createResultSet.

Create a resultset from data retrieved from the server.

public boolean
execute(String
any SQL statement
sql
)

Implements java.sql.Statement.execute.

Executes the given SQL statement, which may return multiple results.

protected final void
execute(CachedQuery cachedQuery, @Nullable ParameterList queryParameters, int flags)

public boolean
execute(String
any SQL statement
sql
,
int
a constant indicating whether auto-generated keys should be made available for retrieval using the method getGeneratedKeys; one of the following constants: Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS
autoGeneratedKeys
)

Implements java.sql.Statement.execute.

Executes the given SQL statement, which may return multiple results, and signals the driver that any auto-generated keys should be made available for retrieval.

public boolean
execute(String
any SQL statement
sql
,
@Nullable int[]
an array of the indexes of the columns in the inserted row that should be made available for retrieval by a call to the method getGeneratedKeys
columnIndexes
)

Implements java.sql.Statement.execute.

Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public boolean
execute(String
any SQL statement
sql
,
@Nullable String[]
an array of the names of the columns in the inserted row that should be made available for retrieval by a call to the method getGeneratedKeys
columnNames
)

Implements java.sql.Statement.execute.

Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public int[]
executeBatch()

Implements java.sql.Statement.executeBatch.

Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.

private boolean
executeCachedSql(String sql, int flags, @Nullable String[] columnNames)

private void
executeInternal(CachedQuery cachedQuery, @Nullable ParameterList queryParameters, int flags)

public long[]
executeLargeBatch()

Overrides default java.sql.Statement.executeLargeBatch.

Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.

public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
int
a flag indicating whether auto-generated keys should be made available for retrieval; one of the following constants: Statement.RETURN_GENERATED_KEYS Statement.NO_GENERATED_KEYS
autoGeneratedKeys
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys produced by this Statement object should be made available for retrieval.

public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
int[]
an array of column indexes indicating the columns that should be returned from the inserted row
columnIndexes
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public long
executeLargeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
@Nullable String[]
an array of the names of the columns that should be returned from the inserted row
columnNames
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public ResultSet
executeQuery(String
an SQL statement to be sent to the database, typically a static SQL SELECT statement
sql
)

Implements java.sql.Statement.executeQuery.

Executes the given SQL statement, which returns a single ResultSet object.

public int
executeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
)

Implements java.sql.Statement.executeUpdate.

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

public int
executeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
int
a flag indicating whether auto-generated keys should be made available for retrieval; one of the following constants: Statement.RETURN_GENERATED_KEYS Statement.NO_GENERATED_KEYS
autoGeneratedKeys
)

Implements java.sql.Statement.executeUpdate.

Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys produced by this Statement object should be made available for retrieval.

public int
executeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
int[]
an array of column indexes indicating the columns that should be returned from the inserted row
columnIndexes
)

Implements java.sql.Statement.executeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public int
executeUpdate(String
an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
sql
,
@Nullable String[]
an array of the names of the columns that should be returned from the inserted row
columnNames
)

Implements java.sql.Statement.executeUpdate.

Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

public boolean
executeWithFlags(String
the query to execute (JDBC-style query)
sql
,
int
additional QueryExecutor flags for execution; these are bitwise-ORed into the default flags.
flags
)

Implements org.postgresql.core.BaseStatement.executeWithFlags.

Execute a query, passing additional query flags.

public boolean
executeWithFlags(CachedQuery
the query to execute (native to PostgreSQL)
simpleQuery
,
int
additional QueryExecutor flags for execution; these are bitwise-ORed into the default flags.
flags
)

Implements org.postgresql.core.BaseStatement.executeWithFlags.

Execute a query, passing additional query flags.

public boolean
executeWithFlags(int
additional QueryExecutor flags for execution; these are bitwise-ORed into the default flags.
flags
)

Implements org.postgresql.core.BaseStatement.executeWithFlags.

Execute a prepared query, passing additional query flags.

public boolean
getAdaptiveFetch()

Implements org.postgresql.PGStatement.getAdaptiveFetch.

Get state of adaptive fetch for statement.

public Connection
getConnection()

Implements java.sql.Statement.getConnection.

Retrieves the Connection object that produced this Statement object.

public int
getFetchDirection()

Implements java.sql.Statement.getFetchDirection.

Retrieves the direction for fetching rows from database tables that is the default for result sets generated from this Statement object.

public @Nullable String
public @NonNegative int
getFetchSize()

Implements java.sql.Statement.getFetchSize.

Retrieves the number of result set rows that is the default fetch size for ResultSet objects generated from this Statement object.

protected boolean
public ResultSet
getGeneratedKeys()

Implements java.sql.Statement.getGeneratedKeys.

Retrieves any auto-generated keys created as a result of executing this Statement object.

public long
getLargeMaxRows()

Overrides default java.sql.Statement.getLargeMaxRows.

Retrieves the maximum number of rows that a ResultSet object produced by this Statement object can contain.

public long
getLargeUpdateCount()

Overrides default java.sql.Statement.getLargeUpdateCount.

Retrieves the current result as an update count; if the result is a ResultSet object or there are no more results, -1 is returned.

public long
getLastOID()

Implements org.postgresql.PGStatement.getLastOID.

Returns the Last inserted/updated oid.

public int
getMaxFieldSize()

Implements java.sql.Statement.getMaxFieldSize.

Retrieves the maximum number of bytes that can be returned for character and binary column values in a ResultSet object produced by this Statement object.

public int
getMaxRows()

Implements java.sql.Statement.getMaxRows.

Retrieves the maximum number of rows that a ResultSet object produced by this Statement object can contain.

public boolean
getMoreResults()

Implements java.sql.Statement.getMoreResults.

Moves to this Statement object's next result, returns true if it is a ResultSet object, and implicitly closes any current ResultSet object(s) obtained with the method getResultSet.

public boolean
getMoreResults(int
one of the following Statement constants indicating what should happen to current ResultSet objects obtained using the method getResultSet: Statement.CLOSE_CURRENT_RESULT, Statement.KEEP_CURRENT_RESULT, or Statement.CLOSE_ALL_RESULTS
current
)

Implements java.sql.Statement.getMoreResults.

Moves to this Statement object's next result, deals with any current ResultSet object(s) according to the instructions specified by the given flag, and returns true if the next result is a ResultSet object.

public BaseConnection
public int
getPrepareThreshold()

Implements org.postgresql.PGStatement.getPrepareThreshold.

Gets the server-side prepare reuse threshold in use for this statement.

public int
getQueryTimeout()

Implements java.sql.Statement.getQueryTimeout.

Retrieves the number of seconds the driver will wait for a Statement object to execute.

public long

Returns:

the current query timeout limit in milliseconds; 0 = unlimited
getQueryTimeoutMs
()

The queryTimeout limit is the number of milliseconds the driver will wait for a Statement to execute.

public @Nullable ResultSet
getResultSet()

Implements java.sql.Statement.getResultSet.

Retrieves the current result as a ResultSet object.

public int
getResultSetConcurrency()

Implements java.sql.Statement.getResultSetConcurrency.

Retrieves the result set concurrency for ResultSet objects generated by this Statement object.

public int
getResultSetHoldability()

Implements java.sql.Statement.getResultSetHoldability.

Retrieves the result set holdability for ResultSet objects generated by this Statement object.

public int
getResultSetType()

Implements java.sql.Statement.getResultSetType.

Retrieves the result set type for ResultSet objects generated by this Statement object.

protected ResultSet
protected TimestampUtils
public int
getUpdateCount()

Implements java.sql.Statement.getUpdateCount.

Retrieves the current result as an update count; if the result is a ResultSet object or there are no more results, -1 is returned.

public @Nullable SQLWarning
getWarnings()

Implements java.sql.Statement.getWarnings.

Retrieves the first warning reported by calls on this Statement object.

private BatchResultHandler
public boolean
isClosed()

Implements java.sql.Statement.isClosed.

Retrieves whether this Statement object has been closed.

public boolean
isCloseOnCompletion()

Implements java.sql.Statement.isCloseOnCompletion.

Returns a value indicating whether this Statement will be closed when all its dependent result sets are closed.

protected boolean

Returns:

true if query is unlikely to be reused
isOneShotQuery
(@Nullable CachedQuery
to check (null if current query)
cachedQuery
)

Returns true if query is unlikely to be reused.

public boolean
isPoolable()

Implements java.sql.Statement.isPoolable.

Returns a value indicating whether the Statement is poolable or not.

public boolean
isUseServerPrepare()

Implements org.postgresql.PGStatement.isUseServerPrepare.

Checks if this statement will be executed as a server-prepared statement.

public boolean
isWrapperFor(Class<?>
a Class defining an interface.
iface
)

Implements java.sql.Wrapper.isWrapperFor.

Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.

private void
public void
setAdaptiveFetch(boolean
desired state of adaptive fetch.
adaptiveFetch
)

Implements org.postgresql.PGStatement.setAdaptiveFetch.

Turn on/off adaptive fetch for statement.

public void
setCursorName(String
the new cursor name, which must be unique within a connection
name
)

Implements java.sql.Statement.setCursorName.

Sets the SQL cursor name to the given String, which will be used by subsequent Statement object execute methods.

public void
setEscapeProcessing(boolean
true to enable escape processing; false to disable it
enable
)

Implements java.sql.Statement.setEscapeProcessing.

Sets escape processing on or off.

public void
setFetchDirection(int
the initial direction for processing rows
direction
)

Implements java.sql.Statement.setFetchDirection.

Gives the driver a hint as to the direction in which rows will be processed in ResultSet objects created using this Statement object.

public void
setFetchSize(@NonNegative int
the number of rows to fetch
rows
)

Implements java.sql.Statement.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 ResultSet objects generated by this Statement.

public void
setLargeMaxRows(long
the new max rows limit; zero means there is no limit
max
)

Overrides default java.sql.Statement.setLargeMaxRows.

Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement object can contain to the given number.

public void
setMaxFieldSize(int
the new column size limit in bytes; zero means there is no limit
max
)

Implements java.sql.Statement.setMaxFieldSize.

Sets the limit for the maximum number of bytes that can be returned for character and binary column values in a ResultSet object produced by this Statement object.

public void
setMaxRows(int
the new max rows limit; zero means there is no limit
max
)

Implements java.sql.Statement.setMaxRows.

Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement object can contain to the given number.

public void
setPoolable(boolean
requests that the statement be pooled if true and that the statement not be pooled if false
poolable
)

Implements java.sql.Statement.setPoolable.

Requests that a Statement be pooled or not pooled.

public void
setPrepareThreshold(int
the new threshold for this statement
newThreshold
)

Implements org.postgresql.PGStatement.setPrepareThreshold.

Sets the reuse threshold for using server-prepared statements.

public void
setQueryTimeout(int
the new query timeout limit in seconds; zero means there is no limit
seconds
)

Implements java.sql.Statement.setQueryTimeout.

Sets the number of seconds the driver will wait for a Statement object to execute to the given number of seconds.

public void
setQueryTimeoutMs(long
- the new query timeout limit in milliseconds
millis
)

Sets the queryTimeout limit.

public void
setUseServerPrepare(boolean
use server prepare
flag
)

Implements org.postgresql.PGStatement.setUseServerPrepare.

Turn on the use of prepared statements in the server (server side prepared statements are unrelated to jdbc PreparedStatements) As of build 302, this method is equivalent to setPrepareThreshold(1).

private void
protected void
public <T> T
unwrap(Class<T>
A Class defining an interface that the result must implement.
iface
)

Implements java.sql.Wrapper.unwrap.

Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.

protected boolean
protected boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait