Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile Client
11g Release 1 (11.1.1)

E17503-02

oracle.adfnmc.java.sql
Interface Statement

All Known Subinterfaces:
CallableStatement, PreparedStatement

public interface Statement

Interface used for executing static SQL statements and returning their results. By default, an object implementing the Statement interface can returns results as ResultSets. For any given Statement object, only one ResultSet can be open at one time. A call to any of the execution methods of Statement will cause any previously created ResultSet object for that Statement to be closed implicitly.

To have multiple ResultSet objects open concurrently, multiple Statement objects must be used.


Field Summary
static int CLOSE_ALL_RESULTS
          Passing this constant to getMoreResults implies that all ResultSet objects previously kept open should be closed.
static int CLOSE_CURRENT_RESULT
          Passing this constant to getMoreResults implies that the current ResultSet object should be closed
static int EXECUTE_FAILED
          Indicates that an error was encountered during execution of a batch statement.
static int KEEP_CURRENT_RESULT
          Passing this constant to getMoreResults implies that the current ResultSet object should not be closed.
static int NO_GENERATED_KEYS
          Indicates that generated keys should not be accessible for retrieval.
static int RETURN_GENERATED_KEYS
          Indicates that generated keys should be accessible for retrieval.
static int SUCCESS_NO_INFO
          Indicates that a batch statement was executed with a successful result, but a count of the number of rows it affected is unavailable.
 
Method Summary
 void addBatch(java.lang.String sql)
          Adds a specified SQL commands to the list of commands for this Statement.
 void cancel()
          Cancels this Statement execution if both the database and the JDBC driver support aborting an SQL statement in flight.
 void clearBatch()
          Clears the current list of SQL commands for this Statement.
 void clearWarnings()
          Clears all SQLWarnings from this Statement.
 void close()
          Releases this Statement's database and JDBC driver resources.
 boolean execute(java.lang.String sql)
          Executes a supplied SQL statement.
 boolean execute(java.lang.String sql, int autoGeneratedKeys)
          Executes a supplied SQL statement.
 boolean execute(java.lang.String sql, int[] columnIndexes)
          Executes the supplied SQL statement.
 boolean execute(java.lang.String sql, java.lang.String[] columnNames)
          Executes the supplied SQL statement.
 int[] executeBatch()
          Submits a batch of SQL commands to the database.
 ResultSet executeQuery(java.lang.String sql)
          Executes a supplied SQL statement.
 int executeUpdate(java.lang.String sql)
          Executes the supplied SQL statement.
 int executeUpdate(java.lang.String sql, int autoGeneratedKeys)
          Executes the supplied SQL statement.
 int executeUpdate(java.lang.String sql, int[] columnIndexes)
          Executes the supplied SQL statement.
 int executeUpdate(java.lang.String sql, java.lang.String[] columnNames)
          Executes the supplied SQL statement.
 Connection getConnection()
          Gets the Connection that produced this Statement.
 int getFetchDirection()
          Gets the default direction for fetching rows for ResultSets generated from this Statement.
 int getFetchSize()
          Gets the default number of rows for a fetch for the ResultSet objects returned from this Statement.
 ResultSet getGeneratedKeys()
          Returns auto generated keys created by executing this Statement.
 int getMaxFieldSize()
          Gets the maximum number of bytes which can be returned for values from Character and Binary values in a ResultSet derived from this Statement.
 int getMaxRows()
          Gets the maximum number of rows that a ResultSet can contain when produced from this Statement.
 boolean getMoreResults()
          Moves to this Statement's next result.
 boolean getMoreResults(int current)
          Moves to this Statement's next result.
 int getQueryTimeout()
          Gets the timeout value for Statement execution.
 ResultSet getResultSet()
          Gets the current result.
 int getResultSetConcurrency()
          Gets the concurrency setting for ResultSet objects generated by this Statement.
 int getResultSetHoldability()
          Gets the cursor hold setting for ResultSet objects generated by this Statement.
 int getResultSetType()
          Gets the ResultSet type setting for ResultSets derived from this Statement.
 int getUpdateCount()
          Gets an update count for the current result if it is not a ResultSet.
 SQLWarning getWarnings()
          Retrieves the first SQLWarning reported by calls on this Statement.
 void setCursorName(java.lang.String name)
          Sets the SQL cursor name.
 void setEscapeProcessing(boolean enable)
          Sets Escape Processing mode.
 void setFetchDirection(int direction)
          Sets the fetch direction - a hint to the JDBC driver about the direction of processing of rows in ResultSets created by this Statement.
 void setFetchSize(int rows)
          Sets the fetch size.
 void setMaxFieldSize(int max)
          Sets the maximum number of bytes for ResultSet columns that contain character or binary values.
 void setMaxRows(int max)
          Sets the maximum number of rows that any ResultSet can contain.
 void setQueryTimeout(int seconds)
          Sets the timeout, in seconds, for queries - how long the driver will allow for completion of a Statement execution.
 

Field Detail

CLOSE_ALL_RESULTS

static final int CLOSE_ALL_RESULTS
Passing this constant to getMoreResults implies that all ResultSet objects previously kept open should be closed.

See Also:
Constant Field Values

CLOSE_CURRENT_RESULT

static final int CLOSE_CURRENT_RESULT
Passing this constant to getMoreResults implies that the current ResultSet object should be closed

See Also:
Constant Field Values

EXECUTE_FAILED

static final int EXECUTE_FAILED
Indicates that an error was encountered during execution of a batch statement.

See Also:
Constant Field Values

KEEP_CURRENT_RESULT

static final int KEEP_CURRENT_RESULT
Passing this constant to getMoreResults implies that the current ResultSet object should not be closed.

See Also:
Constant Field Values

NO_GENERATED_KEYS

static final int NO_GENERATED_KEYS
Indicates that generated keys should not be accessible for retrieval.

See Also:
Constant Field Values

RETURN_GENERATED_KEYS

static final int RETURN_GENERATED_KEYS
Indicates that generated keys should be accessible for retrieval.

See Also:
Constant Field Values

SUCCESS_NO_INFO

static final int SUCCESS_NO_INFO
Indicates that a batch statement was executed with a successful result, but a count of the number of rows it affected is unavailable.

See Also:
Constant Field Values
Method Detail

addBatch

void addBatch(java.lang.String sql)
              throws SQLException
Adds a specified SQL commands to the list of commands for this Statement.

The list of commands is executed by invoking the executeBatch method.

Parameters:
sql - the SQL command as a String. Typically an INSERT or UPDATE statement.
Throws:
SQLException - if an error occurs accessing the database or the database does not support batch updates

cancel

void cancel()
            throws SQLException
Cancels this Statement execution if both the database and the JDBC driver support aborting an SQL statement in flight. This method can be used by one thread to stop a Statement that is being executed on another thread.

Throws:
SQLException - if an error occurs accessing the database

clearBatch

void clearBatch()
                throws SQLException
Clears the current list of SQL commands for this Statement.

Throws:
SQLException - if an error occurs accessing the database or the database does not support batch updates

clearWarnings

void clearWarnings()
                   throws SQLException
Clears all SQLWarnings from this Statement.

Throws:
SQLException - if an error occurs accessing the database

close

void close()
           throws SQLException
Releases this Statement's database and JDBC driver resources.

Using this method to release these resources as soon as possible is strongly recommended. It is not a good idea to rely on these resources being released when the Statement object is finalized during garbage collection. Doing so can result in unpredictable performance characteristics for the application.

Throws:
SQLException - if an error occurs accessing the database

execute

boolean execute(java.lang.String sql)
                throws SQLException
Executes a supplied SQL statement. This may return multiple ResultSets.

Use the getResultSet or getUpdateCount methods to get the first result and getMoreResults to get any subsequent results.

Parameters:
sql - the SQL statement to execute
Returns:
true if the first result is a ResultSet, false if the first result is an update count or if there is no result
Throws:
SQLException - if an error occurs accessing the database

execute

boolean execute(java.lang.String sql,
                int autoGeneratedKeys)
                throws SQLException
Executes a supplied SQL statement. This may return multiple ResultSets. This method allows control of whether auto-generated Keys should be made available for retrieval, if the SQL statement is an INSERT statement.

Use the getResultSet or getUpdateCount methods to get the first result and getMoreResults to get any subsequent results.

Parameters:
sql - the SQL statement to execute
autoGeneratedKeys - a flag indicating whether to make auto generated keys available for retrieval. This parameter must be one of Statement.NO_GENERATED_KEYS or Statement.RETURN_GENERATED_KEYS
Returns:
true if results exists and the first result is a ResultSet, false if the first result is an update count or if there is no result
Throws:
SQLException - if an error occurs accessing the database

execute

boolean execute(java.lang.String sql,
                int[] columnIndexes)
                throws SQLException
Executes the supplied SQL statement. This may return multiple ResultSets. This method allows retrieval of auto generated keys specified by the supplied array of column indexes, if the SQL statement is an INSERT statement.

Use the getResultSet or getUpdateCount methods to get the first result and getMoreResults to get any subsequent results.

Parameters:
sql - the SQL statement to execute
columnIndexes - an array of indexes of the columns in the inserted row which should be made available for retrieval via the getGeneratedKeys method.
Returns:
true if the first result is a ResultSet, false if the first result is an update count or if there is no result
Throws:
SQLException - if an error occurs accessing the database

execute

boolean execute(java.lang.String sql,
                java.lang.String[] columnNames)
                throws SQLException
Executes the supplied SQL statement. This may return multiple ResultSets. This method allows retrieval of auto generated keys specified by the supplied array of column indexes, if the SQL statement is an INSERT statement.

Use the getResultSet or getUpdateCount methods to get the first result and getMoreResults to get any subsequent results.

Parameters:
sql - the SQL statement to execute
columnNames - an array of column names in the inserted row which should be made available for retrieval via the getGeneratedKeys method.
Returns:
true if the first result is a ResultSet, false if the first result is an update count or if there is no result
Throws:
SQLException - if an error occurs accessing the database

executeBatch

int[] executeBatch()
                   throws SQLException
Submits a batch of SQL commands to the database. Returns an array of update counts, if all the commands execute successfully.

If one of the commands in the batch fails, this method can throw a BatchUpdateException and the JDBC driver may or may not process the remaining commands. The JDBC driver must behave consistently with the underlying database, either always continuing or never continuing. If the driver continues processing, the array of results returned contains the same number of elements as there are commands in the batch, with a minimum of one of the elements having the EXECUTE_FAILED value.

Returns:
an array of update counts, with one entry for each command in the batch. The elements are ordered according to the order in which the commands were added to the batch.

  1. If the value of an element is >=0, the corresponding command completed successfully and the value is the update count for that command, which is the number of rows in the database affected by the command.
  2. If the value is SUCCESS_NO_INFO, the command completed successfully but the number of rows affected is unknown.
  3. If the value is EXECUTE_FAILED, the command failed.
Throws:
SQLException - if an error occurs accessing the database

executeQuery

ResultSet executeQuery(java.lang.String sql)
                       throws SQLException
Executes a supplied SQL statement. Returns a single ResultSet.

Parameters:
sql - an SQL statement to execute. Typically a SELECT statement
Returns:
a ResultSet containing the data produced by the SQL statement. Never null.
Throws:
SQLException - if an error occurs accessing the database or if the statement produces anything other than a single ResultSet

executeUpdate

int executeUpdate(java.lang.String sql)
                  throws SQLException
Executes the supplied SQL statement. The statement may be an INSERT, UPDATE or DELETE statement or a statement which returns nothing.

Parameters:
sql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which returns nothing
Returns:
the count of updated rows, or 0 for a statement that returns nothing.
Throws:
SQLException - if an error occurs accessing the database or if the statement produces a ResultSet

executeUpdate

int executeUpdate(java.lang.String sql,
                  int autoGeneratedKeys)
                  throws SQLException
Executes the supplied SQL statement. This method allows control of whether auto-generated Keys should be made available for retrieval.

Parameters:
sql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which does not return anything.
autoGeneratedKeys - a flag that indicates whether to allow retrieval of auto generated keys. Parameter must be one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS
Returns:
the number of updated rows, or 0 if the statement returns nothing.
Throws:
SQLException - if an error occurs accessing the database or if the statement produces a ResultSet

executeUpdate

int executeUpdate(java.lang.String sql,
                  int[] columnIndexes)
                  throws SQLException
Executes the supplied SQL statement. This method allows retrieval of auto generated keys specified by the supplied array of column indexes.

Parameters:
sql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which returns nothing
columnIndexes - an array of indexes of the columns in the inserted row which should be made available for retrieval via the getGeneratedKeys method.
Returns:
the count of updated rows, or 0 for a statement that returns nothing.
Throws:
SQLException - if an error occurs accessing the database or if the statement produces a ResultSet

executeUpdate

int executeUpdate(java.lang.String sql,
                  java.lang.String[] columnNames)
                  throws SQLException
Executes the supplied SQL statement. This method allows retrieval of auto generated keys specified by the supplied array of column names.

Parameters:
sql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which returns nothing
columnNames - an array of column names in the inserted row which should be made available for retrieval via the getGeneratedKeys method.
Returns:
the count of updated rows, or 0 for a statement that returns nothing.
Throws:
SQLException - if an error occurs accessing the database or if the statement produces a ResultSet

getConnection

Connection getConnection()
                         throws SQLException
Gets the Connection that produced this Statement.

Returns:
the Connection
Throws:
SQLException - if an error occurs accessing the database

getFetchDirection

int getFetchDirection()
                      throws SQLException
Gets the default direction for fetching rows for ResultSets generated from this Statement.

Returns:
an integer describing the default fetch direction, one of: ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, ResultSet.FETCH_UNKNOWN
Throws:
SQLException - if an error occurs accessing the database

getFetchSize

int getFetchSize()
                 throws SQLException
Gets the default number of rows for a fetch for the ResultSet objects returned from this Statement.

Returns:
the default fetch size for ResultSets produced by this Statement
Throws:
SQLException - if an error occurs accessing the database

getGeneratedKeys

ResultSet getGeneratedKeys()
                           throws SQLException
Returns auto generated keys created by executing this Statement.

Returns:
a ResultSet containing the auto generated keys - empty if no keys were generated by the Statement
Throws:
SQLException - if an error occurs accessing the database

getMaxFieldSize

int getMaxFieldSize()
                    throws SQLException
Gets the maximum number of bytes which can be returned for values from Character and Binary values in a ResultSet derived from this Statement. This limit applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR types. Any data exceeding the maximum size is abandoned without announcement.

Returns:
the current size limit, where 0 means that there is no limit
Throws:
SQLException - if an error occurs accessing the database

getMaxRows

int getMaxRows()
               throws SQLException
Gets the maximum number of rows that a ResultSet can contain when produced from this Statement. If the limit is exceeded, the excess rows are discarded silently.

Returns:
the current row limit, where 0 means that there is no limit.
Throws:
SQLException - if an error occurs accessing the database

getMoreResults

boolean getMoreResults()
                       throws SQLException
Moves to this Statement's next result. Returns true if it is a ResultSet. Any current ResultSet objects previously obtained with getResultSet() are closed implicitly.

Returns:
true if the next result is a ResultSet, false if the next result is not a ResultSet or if there are no more results. Note that if there is no more data, this method will return false and getUpdateCount will return -1.
Throws:
SQLException - if an error occurs accessing the database

getMoreResults

boolean getMoreResults(int current)
                       throws SQLException
Moves to this Statement's next result. Returns true if the next result is a ResultSet. Any current ResultSet objects previously obtained with getResultSet() are handled as indicated by a supplied Flag parameter.

Parameters:
current - a flag indicating what to do with existing ResultSets. This parameter must be one of Statement.CLOSE_ALL_RESULTS, Statement.CLOSE_CURRENT_RESULT or Statement.KEEP_CURRENT_RESULT.
Returns:
true if the next result exists and is a ResultSet, false if the next result is not a ResultSet or if there are no more results. Note that if there is no more data, this method will return false and getUpdateCount will return -1.
Throws:
SQLException - if an error occurs accessing the database

getQueryTimeout

int getQueryTimeout()
                    throws SQLException
Gets the timeout value for Statement execution. The JDBC driver will wait up to this value for the execution to complete - after the limit is exceeded an SQL Exception is thrown.

Returns:
the current Query Timeout value, where 0 indicates that there is no current timeout.
Throws:
SQLException - if an error occurs accessing the database

getResultSet

ResultSet getResultSet()
                       throws SQLException
Gets the current result. Should only be called once per result.

Returns:
the ResultSet for the current result. null if the result is an update count or if there are no more results.
Throws:
SQLException - if an error occurs accessing the database

getResultSetConcurrency

int getResultSetConcurrency()
                            throws SQLException
Gets the concurrency setting for ResultSet objects generated by this Statement.

Returns:
ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
Throws:
SQLException - if an error occurs accessing the database

getResultSetHoldability

int getResultSetHoldability()
                            throws SQLException
Gets the cursor hold setting for ResultSet objects generated by this Statement.

Returns:
ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
Throws:
SQLException - if there is an error while accessing the database

getResultSetType

int getResultSetType()
                     throws SQLException
Gets the ResultSet type setting for ResultSets derived from this Statement.

Returns:
ResultSet.TYPE_FORWARD_ONLY for a ResultSet where the cursor can only move forward, ResultSet.TYPE_SCROLL_INSENSITIVE for a ResultSet which is Scrollable but is not sensitive to changes made by others, ResultSet.TYPE_SCROLL_SENSITIVE for a ResultSet which is Scrollable but is sensitive to changes made by others
Throws:
SQLException - if there is an error accessing the database

getUpdateCount

int getUpdateCount()
                   throws SQLException
Gets an update count for the current result if it is not a ResultSet.

Returns:
the current result as an update count. -1 if the current result is a ResultSet or if there are no more results
Throws:
SQLException - if an error occurs accessing the database

getWarnings

SQLWarning getWarnings()
                       throws SQLException
Retrieves the first SQLWarning reported by calls on this Statement.

If there are multiple warnings, subsequent warnings are chained to the first one.

The chain or warnings is cleared each time the Statement is executed.

Warnings associated with reads from the ResultSet returned from executing a Statement will be attached to the ResultSet, not the Statement object.

Returns:
an SQLWarning, null if there are no warnings
Throws:
SQLException - if an error occurs accessing the database

setCursorName

void setCursorName(java.lang.String name)
                   throws SQLException
Sets the SQL cursor name. This name is used by subsequent Statement execute methods.

Cursor names must be unique within one Connection.

With the Cursor name set, it can then be utilized in SQL positioned update or delete statements to determine the current row in a ResultSet generated from this Statement. The positioned update or delete must be done with a different Statement than this one.

Parameters:
name - the Cursor name as a String,
Throws:
SQLException - if an error occurs accessing the database

setEscapeProcessing

void setEscapeProcessing(boolean enable)
                         throws SQLException
Sets Escape Processing mode.

If Escape Processing is on, the JDBC driver will do escape substitution on an SQL statement before sending it for execution. This does not apply to PreparedStatements since they are processed when created, before this method can be called.

Parameters:
enable - true to set escape processing mode on, false to turn it off.
Throws:
SQLException - if an error occurs accessing the database

setFetchDirection

void setFetchDirection(int direction)
                       throws SQLException
Sets the fetch direction - a hint to the JDBC driver about the direction of processing of rows in ResultSets created by this Statement. The default fetch direction is FETCH_FORWARD.

Parameters:
direction - which fetch direction to use. This parameter should be one of ResultSet.FETCH_UNKNOWN, ResultSet.FETCH_FORWARD or ResultSet.FETCH_REVERSE
Throws:
SQLException - if there is an error while accessing the database or if the fetch direction is unrecognized

setFetchSize

void setFetchSize(int rows)
                  throws SQLException
Sets the fetch size. This is a hint to the JDBC driver about how many rows should be fetched from the database when more are required by application processing.

Parameters:
rows - the number of rows that should be fetched. 0 tells the driver to ignore the hint. Should be less than getMaxRows for this statement. Should not be negative.
Throws:
SQLException - if an error occurs accessing the database, or if the rows parameter is out of range.

setMaxFieldSize

void setMaxFieldSize(int max)
                     throws SQLException
Sets the maximum number of bytes for ResultSet columns that contain character or binary values. This applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR fields. Any data exceeding the maximum size is abandoned without announcement.

Parameters:
max - the maximum field size in bytes. O means "no limit".
Throws:
SQLException - if an error occurs accessing the database or the max value is <0.

setMaxRows

void setMaxRows(int max)
                throws SQLException
Sets the maximum number of rows that any ResultSet can contain. If the number of rows exceeds this value, the additional rows are silently discarded.

Parameters:
max - the maximum number of rows. 0 means "no limit".
Throws:
SQLException - if an error occurs accessing the database or if max <0.

setQueryTimeout

void setQueryTimeout(int seconds)
                     throws SQLException
Sets the timeout, in seconds, for queries - how long the driver will allow for completion of a Statement execution. If the timeout is exceeded, the query will throw an SQLException.

Parameters:
seconds - timeout in seconds. 0 means no timeout ("wait forever")
Throws:
SQLException - if an error occurs accessing the database or if seconds <0.

Oracle Fusion Middleware Java API Reference for Oracle ADF Mobile Client
11g Release 1 (11.1.1)

E17503-02

Copyright © 2011, Oracle and/or its affiliates. All rights reserved.