|
Java Platform 1.2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
The object used for executing a static SQL statement and obtaining the results produced by it.
Only one ResultSet per Statement can be open at any point in
time. Therefore, if the reading of one ResultSet is interleaved
with the reading of another, each must have been generated by
different Statements. All statement execute
methods implicitly
close a statment's current ResultSet if an open one exists.
Connection.createStatement()
,
ResultSet
Method Summary | |
void |
addBatch(String sql)
JDBC 2.0 Adds a SQL command to the current batch of commmands for the statement. |
void |
cancel()
Cancels this Statement object if both the DBMS and
driver support aborting an SQL statement. |
void |
clearBatch()
JDBC 2.0 Makes the set of commands in the current batch empty. |
void |
clearWarnings()
Clears all the warnings reported on this Statement
object. |
void |
close()
Releases this Statement object's database
and JDBC resources immediately instead of waiting for
this to happen when it is automatically closed. |
boolean |
execute(String sql)
Executes a SQL statement that may return multiple results. |
int[] |
executeBatch()
JDBC 2.0 Submits a batch of commands to the database for execution. |
ResultSet |
executeQuery(String sql)
Executes a SQL statement that returns a single ResultSet. |
int |
executeUpdate(String sql)
Executes an SQL INSERT, UPDATE or DELETE statement. |
Connection |
getConnection()
JDBC 2.0 Returns the Connection object
that produced this Statement object. |
int |
getFetchDirection()
JDBC 2.0 Retrieves the direction for fetching rows from database tables that is the default for result sets generated from this Statement object. |
int |
getFetchSize()
JDBC 2.0 Retrieves the number of result set rows that is the default fetch size for result sets generated from this Statement object. |
int |
getMaxFieldSize()
Returns the maximum number of bytes allowed for any column value. |
int |
getMaxRows()
Retrieves the maximum number of rows that a ResultSet can contain. |
boolean |
getMoreResults()
Moves to a Statement's next result. |
int |
getQueryTimeout()
Retrieves the number of seconds the driver will wait for a Statement to execute. |
ResultSet |
getResultSet()
Returns the current result as a ResultSet object. |
int |
getResultSetConcurrency()
JDBC 2.0 Retrieves the result set concurrency. |
int |
getResultSetType()
JDBC 2.0 Determine the result set type. |
int |
getUpdateCount()
Returns the current result as an update count; if the result is a ResultSet or there are no more results, -1 is returned. |
SQLWarning |
getWarnings()
Retrieves the first warning reported by calls on this Statement. |
void |
setCursorName(String name)
Defines the SQL cursor name that will be used by subsequent Statement execute methods. |
void |
setEscapeProcessing(boolean enable)
Sets escape processing on or off. |
void |
setFetchDirection(int direction)
JDBC 2.0 Gives the driver a hint as to the direction in which the rows in a result set will be processed. |
void |
setFetchSize(int rows)
JDBC 2.0 Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed. |
void |
setMaxFieldSize(int max)
Sets the limit for the maximum number of bytes in a column to the given number of bytes. |
void |
setMaxRows(int max)
Sets the limit for the maximum number of rows that any ResultSet can contain to the given number. |
void |
setQueryTimeout(int seconds)
Sets the number of seconds the driver will wait for a Statement to execute to the given number of seconds. |
Method Detail |
public ResultSet executeQuery(String sql) throws SQLException
sql
- typically this is a static SQL SELECT statementpublic int executeUpdate(String sql) throws SQLException
sql
- a SQL INSERT, UPDATE or DELETE statement or a SQL
statement that returns nothingpublic void close() throws SQLException
Statement
object's database
and JDBC resources immediately instead of waiting for
this to happen when it is automatically closed.
It is generally good practice to release resources as soon as
you are finished with them to avoid tying up database
resources.
Note: A Statement is automatically closed when it is garbage collected. When a Statement is closed, its current ResultSet, if one exists, is also closed.
public int getMaxFieldSize() throws SQLException
public void setMaxFieldSize(int max) throws SQLException
max
- the new max column size limit; zero means unlimitedpublic int getMaxRows() throws SQLException
public void setMaxRows(int max) throws SQLException
max
- the new max rows limit; zero means unlimitedpublic void setEscapeProcessing(boolean enable) throws SQLException
enable
- true to enable; false to disablepublic int getQueryTimeout() throws SQLException
public void setQueryTimeout(int seconds) throws SQLException
seconds
- the new query timeout limit in seconds; zero means
unlimitedpublic void cancel() throws SQLException
Statement
object if both the DBMS and
driver support aborting an SQL statement.
This method can be used by one thread to cancel a statement that
is being executed by another thread.public SQLWarning getWarnings() throws SQLException
The warning chain is automatically cleared each time a statement is (re)executed.
Note: If you are processing a ResultSet, any warnings associated with ResultSet reads will be chained on the ResultSet object.
public void clearWarnings() throws SQLException
Statement
object. After a call to this method,
the method getWarnings
will return
null until a new warning is reported for this Statement.public void setCursorName(String name) throws SQLException
execute
methods. This name can then be
used in SQL positioned update/delete statements to identify the
current row in the ResultSet generated by this statement. If
the database doesn't support positioned update/delete, this
method is a noop. To insure that a cursor has the proper isolation
level to support updates, the cursor's SELECT statement should be
of the form 'select for update ...'. If the 'for update' phrase is
omitted, positioned updates may fail.
Note: By definition, positioned update/delete execution must be done by a different Statement than the one which generated the ResultSet being used for positioning. Also, cursor names must be unique within a connection.
name
- the new cursor name, which must be unique within
a connectionpublic boolean execute(String sql) throws SQLException
execute
,
getMoreResults
, getResultSet
,
and getUpdateCount
let you navigate through multiple results.
The execute
method executes a SQL statement and indicates the
form of the first result. You can then use getResultSet or
getUpdateCount to retrieve the result, and getMoreResults to
move to any subsequent result(s).sql
- any SQL statementgetResultSet()
,
getUpdateCount()
,
getMoreResults()
public ResultSet getResultSet() throws SQLException
ResultSet
object.
This method should be called only once per result.execute(java.lang.String)
public int getUpdateCount() throws SQLException
execute(java.lang.String)
public boolean getMoreResults() throws SQLException
execute(java.lang.String)
public void setFetchDirection(int direction) throws SQLException
Note that this method sets the default fetch direction for
result sets generated by this Statement
object.
Each result set has its own methods for getting and setting
its own fetch direction.
direction
- the initial direction for processing rowspublic int getFetchDirection() throws SQLException
Statement
object.
If this Statement
object has not set
a fetch direction by calling the method setFetchDirection
,
the return value is implementation-specific.Statement
objectpublic void setFetchSize(int rows) throws SQLException
rows
- the number of rows to fetchpublic int getFetchSize() throws SQLException
Statement
object.
If this Statement
object has not set
a fetch size by calling the method setFetchSize
,
the return value is implementation-specific.Statement
objectpublic int getResultSetConcurrency() throws SQLException
public int getResultSetType() throws SQLException
public void addBatch(String sql) throws SQLException
sql
- typically this is a static SQL INSERT or UPDATE statementpublic void clearBatch() throws SQLException
public int[] executeBatch() throws SQLException
public Connection getConnection() throws SQLException
Connection
object
that produced this Statement
object.
|
Java Platform 1.2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |