Top Description Fields Methods
java.sql

public Interface Statement

extends Wrapper, AutoCloseable
Known Direct Subinterfaces
java.sql.PreparedStatement
Imports
java.util.regex.Pattern

The object used for executing a static SQL statement and returning the results it produces.

By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a current ResultSet object of the statement if an open one exists.

Since
1.1
See Also
Connection#createStatement, ResultSet

Field Summary

Modifier and TypeField and Description
public static final int
CLOSE_ALL_RESULTS

The constant indicating that all ResultSet objects that have previously been kept open should be closed when calling getMoreResults.

public static final int
CLOSE_CURRENT_RESULT

The constant indicating that the current ResultSet object should be closed when calling getMoreResults.

public static final int
EXECUTE_FAILED

The constant indicating that an error occurred while executing a batch statement.

public static final int
KEEP_CURRENT_RESULT

The constant indicating that the current ResultSet object should not be closed when calling getMoreResults.

public static final int
NO_GENERATED_KEYS

The constant indicating that generated keys should not be made available for retrieval.

public static final int
RETURN_GENERATED_KEYS

The constant indicating that generated keys should be made available for retrieval.

public static final int
SUCCESS_NO_INFO

The constant indicating that a batch statement executed successfully but that no count of the number of rows it affected is available.

Method Summary

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

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

public void
cancel()

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

public void
clearBatch()

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

public void
clearWarnings()

Clears all the warnings reported on this Statement object.

public void
close()

Redeclares java.lang.AutoCloseable.close.

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

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

public default String

Returns:

A simple SQL identifier or a delimited identifier
enquoteIdentifier
(String
a SQL identifier
identifier
,
boolean
indicates if a simple SQL identifier should be returned as a quoted identifier
alwaysQuote
)

Returns a SQL identifier.

public default String

Returns:

A string enclosed by single quotes with every single quote converted to two single quotes
enquoteLiteral
(String
a character string
val
)

Returns a String enclosed in single quotes.

public default 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'.
enquoteNCharLiteral
(String
a character string
val
)

Returns a String representing a National Character Set Literal enclosed in single quotes and prefixed with a upper case letter N.

public boolean

Returns:

true if the first result is a ResultSet object; false if it is an update count or there are no results
execute
(String
any SQL statement
sql
)

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

public boolean

Returns:

true if the first result is a ResultSet object; false if it is an update count or there are no results
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
)

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

Returns:

true if the first result is a ResultSet object; false if it is an update count or there are no results
execute
(String
any SQL statement
sql
,
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
)

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

Returns:

true if the next result is a ResultSet object; false if it is an update count or there are no more results
execute
(String
any SQL statement
sql
,
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
)

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[]

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.
executeBatch
()

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

public default long[]

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.
executeLargeBatch
()

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

public default long

Returns:

either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
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
)

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 default long

Returns:

either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
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
)

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 default long

Returns:

either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
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
)

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 default long

Returns:

either the row count for INSERT, UPDATE, or DELETE statements, or 0 for SQL statements that return nothing
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
,
String[]
an array of the names of the columns that should be returned from the inserted row
columnNames
)

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

Returns:

a ResultSet object that contains the data produced by the given query; never null
executeQuery
(String
an SQL statement to be sent to the database, typically a static SQL SELECT statement
sql
)

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

public int

Returns:

either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
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
)

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

Returns:

either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
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
)

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

Returns:

either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
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
)

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

Returns:

either the row count for INSERT, UPDATE, or DELETE statements, or 0 for SQL statements that return nothing
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
,
String[]
an array of the names of the columns that should be returned from the inserted row
columnNames
)

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 Connection

Returns:

the connection that produced this statement
getConnection
()

Retrieves the Connection object that produced this Statement object.

public int

Returns:

the default fetch direction for result sets generated from this Statement object
getFetchDirection
()

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

public int

Returns:

the default fetch size for result sets generated from this Statement object
getFetchSize
()

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

public ResultSet

Returns:

a ResultSet object containing the auto-generated key(s) generated by the execution of this Statement object
getGeneratedKeys
()

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

public default long

Returns:

the current maximum number of rows for a ResultSet object produced by this Statement object; zero means there is no limit
getLargeMaxRows
()

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

public default long

Returns:

the current result as an update count; -1 if the current result is a ResultSet object or there are no more results
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 int

Returns:

the current column size limit for columns storing character and binary values; zero means there is no limit
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

Returns:

the current maximum number of rows for a ResultSet object produced by this Statement object; zero means there is no limit
getMaxRows
()

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

public boolean

Returns:

true if the next result is a ResultSet object; false if it is an update count or there are no more results
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

Returns:

true if the next result is a ResultSet object; false if it is an update count or there are no more results
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
)

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 int

Returns:

the current query timeout limit in seconds; zero means there is no limit
getQueryTimeout
()

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

public ResultSet

Returns:

the current result as a ResultSet object or null if the result is an update count or there are no more results
getResultSet
()

Retrieves the current result as a ResultSet object.

public int

Returns:

either ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
getResultSetConcurrency
()

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

public int

Returns:

either ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
getResultSetHoldability
()

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

public int

Returns:

one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
getResultSetType
()

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

public int

Returns:

the current result as an update count; -1 if the current result is a ResultSet object or there are no more results
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 SQLWarning

Returns:

the first SQLWarning object or null if there are no warnings
getWarnings
()

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

public boolean

Returns:

true if this Statement object is closed; false if it is still open
isClosed
()

Retrieves whether this Statement object has been closed.

public boolean

Returns:

true if the Statement will be closed when all of its dependent result sets are closed; false otherwise
isCloseOnCompletion
()

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

public boolean

Returns:

true if the Statement is poolable; false otherwise
isPoolable
()

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

public default boolean

Returns:

true if a simple SQL identifier, false otherwise
isSimpleIdentifier
(String
a SQL identifier
identifier
)

Retrieves whether identifier is a simple SQL identifier.

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

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
)

Sets escape processing on or off.

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

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(int
the number of rows to fetch
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 for ResultSet objects generated by this Statement.

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

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
)

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
)

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
)

Requests that a Statement be pooled or not pooled.

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

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

Inherited from java.sql.Wrapper:
isWrapperForunwrap