Interface Statement

public interface Statement extends Object

Statement objects are used to create database and driver resources before and during the execution of static SQL statements. They are also used to obtain the SQL statements’ results after being executed within the database. The results, if they are of the form of rows of data, must be retrieved using ResultSets. Note that a SQL statement can return multiple results, but not at the same time. If necessary, instantiate different Statement objects to fetch different ResultSets simultaneously.

See also: createStatement, ResultSet

Methods

addBatch

public void addBatch(String sql) throws SQLException

This adds a SQL command to the current batch of commands for the statement. A SQLException is thrown if the driver doesn’t support batch statements.

Parameters:

sql:

A SQL statement

cancel

public void cancel() throws SQLException

cancel() is used to terminate the execution of a statement. It can be used only within a thread separate from that executing the statement.

clearBatch

public void clearBatch() throws SQLException

This deletes the set of commands in the current batch. A SQLException is thrown if the driver doesn’t support batch statements.

clearWarnings

public void clearWarnings() throws SQLException 

This clears the chain of SQLWarnings for the current Statement.

close

public void close() throws SQLException

close() releases a Statement’s database and JDBC driver resources.

execute

public boolean execute(String sql) throws SQLException

This method executes a SQL statement. The statement can return multiple results, that is, result sets and update counts. In this case, the execute(), getMoreResults(), getResultSet(), and getUpdateCount() methods enable you to fetch those results. execute() indicates whether the first result is a ResultSet or an update count. getResultSet() and getUpdateCount() are used to retrieve the result, and getMoreResults() is used to discover subsequent results, if any.

Parameters:

sql:

A SQL statement

Returns: true if the first result is a ResultSet; false if it is an integer

See also: getResultSet, getUpdateCount, getMoreResults

execute

public int execute(String sql, int flag) throws SQLException

This method executes a SQL statement. The statement can return multiple results, that is, result sets and update counts. In this case, the execute(), getMoreResults(), getResultSet(), and getUpdateCount() methods enable you to fetch those results. execute() indicates whether the first result is a ResultSet or an update count. getResultSet() and getUpdateCount() are used to retrieve the result, and getMoreResults() is used to discover subsequent results, if any.

Parameters:

sql:

A SQL statement

flag:

A flag indicating that auto-generated keys should be returned

Returns: true if the first result is a ResultSet; false if it is an integer

See also: getResultSet, getUpdateCount, getMoreResults

execute

public int execute(String sql, int[] columnIndexes) throws SQLException

This method executes a SQL statement. The statement can return multiple results, that is, result sets and update counts. In this case, the execute(), getMoreResults(),getResultSet(), and getUpdateCount() methods enable you to fetch those results. execute() indicates whether the first result is a ResultSet or an update count. getResultSet() and getUpdateCount() are used to retrieve the result, and getMoreResults() is used to discover subsequent results, if any.

Parameters:

sql:

A SQL statement

columnIndexes:

An array of the ordinals of the columns that should be returned from the inserted or updated rows, if any

Returns: true if the first result is a ResultSet; false if it is an integer

See also: getResultSet, getUpdateCount, getMoreResults

execute

public int execute(String sql, String[] columnNames) throws SQLException

This method executes a SQL statement. The statement can return multiple results, that is, result sets and update counts. In this case, the execute(), getMoreResults(), getResultSet(), and getUpdateCount() methods enable you to fetch those results. execute() indicates whether the first result is a ResultSet or an update count. getResultSet() and getUpdateCount() are used to retrieve the result, and getMoreResults() is used to discover subsequent results, if any.

Parameters:

sql:

A SQL statement

columnNames:

An array of the names of the columns that should be returned from the inserted or updated rows, if any

Returns: true if the first result is a ResultSet; false if it is an integer

See also: getResultSet, getUpdateCount, getMoreResults

executeBatch

public int[] executeBatch() throws SQLException

This method executes the statements contained in the batch. The array that is returned provides an update count per statement. If the value of the update count is SUCCESS_NO_INFO, it means that the number of rows affected isn’t known. A value of EXECUTE_FAILED indicates that the statement failed to execute successfully and occurs only if a driver continues to process commands after a command fails.

Returns: An array of update counts. A SQLException is thrown if a database access error occurs or the driver doesn’t support batch statements. A BatchUpdateException is thrown if one of the commands of the batch fails to execute.

executeQuery

public ResultSet executeQuery(String sql) throws SQLException

Unlike execute(), executeQuery() is used to execute a SQL statement that returns a single ResultSet.

Parameters:

sql:

A SQL SELECT statement

Returns: A ResultSet containing the result rows, if any

executeUpdate

public int executeUpdate(String sql) throws SQLException

This executes a statement that returns an update count or just nothing (for example: SQL INSERT, UPDATE, or DELETE statements, or a SQL DDL statement such as CREATE TABLE).

Parameters:

sql:

A SQL statement that returns an integer or nothing

Returns: The update count for SQL INSERT, UPDATE, or DELETE; 0 for others

executeUpdate

public int executeUpdate(String sql, int flag) throws SQLException

This executes a statement that returns an update count or just nothing (for example: SQL INSERT, UPDATE, or DELETE statements, or a SQL DDL statement such as CREATE TABLE).

Parameters:

sql:

A SQL statement that returns an integer or nothing

flag:

Indicates whether to return generated keys with one of the following:

  • Statement.RETURN_GENERATED_KEYS

  • Statement.NO_GENERATED_KEYS

Returns: The update count for SQL INSERT, UPDATE, or DELETE; 0 for others

executeUpdate

public int executeUpdate(String sql, int[] columnIndexes) throws SQLException

This executes a statement that returns an update count or just nothing (for example: SQL INSERT, UPDATE, or DELETE statements, or a SQL DDL statement such as CREATE TABLE).

Parameters:

sql:

A SQL statement that returns an integer or nothing

columnIndexes:

An array of the ordinals of the columns that should be returned from the inserted or updated rows

Returns: The update count for SQL INSERT, UPDATE, or DELETE; 0 for others

executeUpdate

public int executeUpdate(String sql, String[] columnNames) throws SQLException

This executes a statement that returns an update count or just nothing (for example: SQL INSERT, UPDATE, or DELETE statements, or a SQL DDL statement such as CREATE TABLE).

Parameters:

sql:

A SQL statement that returns an integer or nothing

columnNames:

An array of the name of the columns that should be returned from the inserted or updated rows

Returns: The update count for SQL INSERT, UPDATE, or DELETE; 0 for others

getConnection

public Connection getConnection() throws SQLException

This gets the connection object used to create the statement.

Returns: The connection that produced the statement

getGeneratedKeys

public ResultSet getGeneratedKeys() throws SQLException

This returns any auto-generated keys from the current statement or an empty result set if there is no generated key.

Returns: The key or keys in a result set object

getMoreResults

public boolean getMoreResults(int current) throws SQLException

This checks if there is another result set or update count available for retrieval. There are no more results when the following is true: (!getMoreResults() && (getUpdateCount() == -1)

Parameters:

current:

One of the following flags, indicating what happens to the previous result set:

  • CLOSE_CURRENT_RESULT

  • KEEP_CURRENT_RESULT

  • CLOSE_ALL_RESULTS

Returns: true if the next result is a ResultSet object; false if it is an update count or there are no more results

getResultSet

public ResultSet getResultSet() throws SQLException

getResultSet() is used to get the current result as a ResultSet. It can be called only once per result.

Returns: The current result as a ResultSet, or null if the result is an integer or there are no more results

See also: execute

getResultSetHoldability

public int getResultSetHoldability() throws SQLException

This returns the result set holdability for result sets generated by the statement.

Returns: One of the following:

  • ResultSet.HOLD_CURSORS_OVER_COMMIT

  • ResultSet.CLOSE_CURSORS_AT_COMMIT

getUpdateCount

public int getUpdateCount() throws SQLException

getUpdateCount() returns the current result as an update count that represents the number of rows affected by the statement. getUpdateCount can also return -1 if the result is a ResultSet or there are no more results. It can be called only once per result.

Returns: The current result as an update count, or -1 if it is a ResultSet or there are no more results

See also: execute

getMaxFieldSize

public int getMaxFieldSize() throws SQLException

This method returns the maximum length of data returned for any column value. It applies only to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR columns.

Returns: The current maximum column size limit or zero if unlimited

getMaxRows

public int getMaxRows() throws SQLException

This method returns the maximum number of rows allowed for a ResultSet. Excessive rows are discarded.

Returns: The current maximum row limit or zero if unlimited

getMoreResults

public boolean getMoreResults() throws SQLException

getMoreResults() is used to navigate results. If true is returned, the current result is a ResultSet. If false, the result is an update count or there are no more results. (There are no more results when (!getMoreResults() && (getUpdateCount() == -1).) Note that getMoreResults() implicitly closes any current ResultSet obtained with getResultSet.

Returns: true if the next result is a ResultSet; false if it is an integer or there are no more results

See also: execute

getQueryTimeout

public int getQueryTimeout() throws SQLException

This specifies that a driver can wait a number of seconds for a Statement to execute. If the limit is exceeded, a SQLException is thrown.

Returns: The current query time-out limit in seconds or zero if unlimited

getFetchDirection

public int getFetchDirection() throws SQLException

This gets the fetch direction of rows for result sets generated by the statement.

Returns: The fetch direction for result sets

getFetchSize

public int getFetchSize() throws SQLException

This returns the default fetch size for result sets generated from the statement object.

Returns: The fetch size for result sets

getResultSetConcurrency

public int getResultSetConcurrency() throws SQLException

This returns the result set concurrency for result sets generated by the statement.

Returns: One of the following:

  • ResultSet.CONCUR_READ_ONLY

  • ResultSet.CONCUR_UPDATABLE

getResultSetType

public int getResultSetType() throws SQLException

This returns the result set type for result sets generated by the statement.

Returns: One of the following:

  • ResultSet.TYPE_FORWARD_ONLY

  • ResultSet.TYPE_SCROLL_INSENSITIVE

  • ResultSet.TYPE_SCROLL_SENSITIVE

getWarnings

public SQLWarning getWarnings() throws SQLException

Statement and ResultSet warnings are chained together. This method is used to get the first SQLWarning of the chain. The chain is cleared each time a statement is executed.

Returns: The first SQLWarning or null

setCursorName

public void setCursorName(String name) throws SQLException

This method sets the SQL cursor name for the current Statement. The cursor name can then be used in SQL positioned update or delete statements to identify the current row in the ResultSet. Note that cursor names must be unique within a Connection.

Parameters:

name:

The cursor name

setEscapeProcessing

public void setEscapeProcessing(boolean enable) throws SQLException

A driver escapes substitution by default unless this method has been invoked with a parameter of Boolean value false.

Parameters:

enable:

true enables escape substitution; false disables it.

setMaxFieldSize

public void setMaxFieldSize(int max) throws SQLException

This limits the size of data that can be returned for any column value. This applies only to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR columns.

Parameters:

max:

The maximum column size limit or zero for unlimited

setMaxRows

public void setMaxRows(int max) throws SQLException

setMaxRows() can be used to limit the rows returned by a query. Excessive rows are silently discarded.

Parameters:

max:

The maximum rows limit or zero for unlimited

setFetchDirection

public void setFetchDirection(int direction) throws SQLException

This indicates the direction in which the rows of a ResultSet have to be processed. A SQLException is thrown if a database access error occurs or if the parameter value is incorrect.

Parameters:

direction:

The initial direction for processing rows, as indicated by one of the following:

  • ResultSet.FETCH_FORWARD

  • ResultSet.FETCH_REVERSE

  • ResultSet.FETCH_UNKNOWN

setFetchSize

public void setFetchSize(int rows) throws SQLException

This indicates the number of rows to be fetched at once when executing the statement.

Parameters:

rows:

The number of rows to fetch. 0 means no default size.

setQueryTimeout

public void setQueryTimeout(int seconds) throws SQLException

This specifies that a driver can wait a number of seconds for a Statement to execute. If the limit is exceeded, a SQLException is thrown.

Parameters:

seconds:

The query time-out limit in seconds or zero for unlimited



JDBC 3. 0. JAVA Database Connectivity
JDBC 3: Java Database Connectivity
ISBN: 0764548751
EAN: 2147483647
Year: 2002
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net