|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.objectweb.cjdbc.driver.Statement
A Statement
object is 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 Statements
execute
methods implicitly close a statement's current ResultSet
if an
open one exists.
Statement
,
DriverResultSet
Field Summary | |
protected java.util.Vector |
batch
Vector for batch commands |
protected Connection |
connection
The connection that created us |
private java.lang.String |
cursorName
Cursor name used jointly with fetch size |
protected boolean |
escapeProcessing
Should the driver to escape processing before sending to the DB? |
private int |
fetchDirection
Direction for fetching rows from ResultSet (note that this hint is currently ignored |
private int |
fetchSize
Default ResultSet fetch size |
protected java.sql.ResultSet |
generatedKeys
Auto generated keys |
protected int |
generatedKeysFlag
|
private int |
maxFieldSize
Maximum field size (unused) |
private int |
maxRows
Maximum number of rows |
protected java.sql.ResultSet |
result
The current result for a read request |
private int |
resultSetConcurrency
ResultSet Concurrency defaults to CONCUR_READ_ONLY |
private int |
resultSetType
Type of the ResultSet defaults to TYPE_FORWARD_ONLY |
private int |
timeout
Query timeout in seconds (0 means no timeout) |
protected int |
updateCount
The update count for a write request |
private java.sql.SQLWarning |
warnings
The warnings chain |
Fields inherited from interface java.sql.Statement |
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO |
Constructor Summary | |
Statement(Connection c)
Creates a new Statement instance. |
Method Summary | |
void |
addBatch(java.lang.String sql)
Adds sql to the current list of commands. |
void |
cancel()
Could be use by one thread to cancel a statement that is being executed by another thread. |
void |
clearBatch()
Empties the current list of commands. |
void |
clearWarnings()
After this call, getWarnings returns null
until a new warning is reported for this Statement . |
void |
close()
In many cases, it is desirable to immediately release a Statement's database and JDBC resources instead of waiting for this to happen when it is automatically closed. |
boolean |
execute(java.lang.String sql)
Execute a SQL statement that may return multiple results. |
boolean |
execute(java.lang.String sql,
int 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. |
boolean |
execute(java.lang.String sql,
int[] 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. |
boolean |
execute(java.lang.String sql,
java.lang.String[] 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. |
int[] |
executeBatch()
Execute a batch of commands |
java.sql.ResultSet |
executeQuery(java.lang.String sql)
Execute a SQL statement that returns a single ResultSet |
protected java.sql.ResultSet |
executeQuery(java.lang.String sqlSkeleton,
java.lang.String sqlQuery)
Execute a SQL statement that returns a single ResultSet |
int |
executeUpdate(java.lang.String sql)
Execute a SQL INSERT, UPDATE or DELETE statement. |
int |
executeUpdate(java.lang.String sql,
int 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. |
int |
executeUpdate(java.lang.String sql,
int[] 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. |
int |
executeUpdate(java.lang.String sql,
java.lang.String[] 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. |
protected int |
executeUpdateWithSkeleton(java.lang.String sqlSkeleton,
java.lang.String sqlQuery)
Execute a SQL INSERT, UPDATE or DELETE statement. |
java.sql.Connection |
getConnection()
Retrieve the connection that created this Statement object |
int |
getFetchDirection()
|
int |
getFetchSize()
|
java.sql.ResultSet |
getGeneratedKeys()
Retrieves any auto-generated keys created as a result of executing this Statement object. |
int |
getMaxFieldSize()
The maxFieldSize limit (in bytes) is the maximum amount of data returned for any column value; it only applies to BINARY ,
VARBINARY ,LONGVARBINARY ,CHAR ,
VARCHAR and LONGVARCHAR columns. |
int |
getMaxRows()
The maxRows limit is set to limit the number of rows that any ResultSet can contain. |
boolean |
getMoreResults()
Multiple results are not suppoted so this method always return false and reset the update count to -1. |
boolean |
getMoreResults(int 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.
|
int |
getQueryTimeout()
The queryTimeout limit is the number of seconds the driver will wait for a Statement to execute. |
java.sql.ResultSet |
getResultSet()
Returns the current result as a ResultSet . |
int |
getResultSetConcurrency()
Retrieve the concurrency mode for the ResultSet . |
int |
getResultSetHoldability()
Retrieves the result set holdability for ResultSet objects
generated by this Statement object. |
int |
getResultSetType()
Retrieve the type of the generated ResultSet . |
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. |
java.sql.SQLWarning |
getWarnings()
The first warning reported by calls on this Statement is returned. |
private boolean |
isClosed()
Test if this statement is closed. |
void |
setCursorName(java.lang.String name)
Defines the SQL cursor name that will be used by subsequent execute methods. |
void |
setEscapeProcessing(boolean enable)
If escape scanning is on (the default), the driver will do escape substitution before sending the SQL to the database. |
void |
setFetchDirection(int direction)
|
void |
setFetchSize(int rows)
Set the default fetch size for the produced ResultSet. |
void |
setMaxFieldSize(int max)
Sets the maxFieldSize . |
void |
setMaxRows(int max)
Sets the maximum number of rows that any ResultSet can
contain. |
void |
setQueryTimeout(int seconds)
Sets the number of seconds the driver will wait for a Statement object to execute. |
void |
setResultSetConcurrency(int value)
|
void |
setResultSetType(int value)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Connection connection
protected java.util.Vector batch
private java.sql.SQLWarning warnings
protected java.sql.ResultSet result
protected int updateCount
private int timeout
private int fetchSize
private java.lang.String cursorName
private int resultSetType
private int resultSetConcurrency
private int maxFieldSize
private int maxRows
private int fetchDirection
protected boolean escapeProcessing
protected java.sql.ResultSet generatedKeys
protected int generatedKeysFlag
Constructor Detail |
public Statement(Connection c)
Statement
instance.
c
- the Connection
that created usMethod Detail |
public void addBatch(java.lang.String sql) throws java.sql.SQLException
addBatch
in interface java.sql.Statement
sql
- an SQL statement that returns an update count (INSERT or UPDATE)
java.sql.SQLException
- if an error occurspublic void cancel() throws java.sql.SQLException
cancel
in interface java.sql.Statement
java.sql.SQLException
- if an error occurspublic void clearBatch() throws java.sql.SQLException
clearBatch
in interface java.sql.Statement
java.sql.SQLException
- if an error occurspublic void clearWarnings() throws java.sql.SQLException
getWarnings
returns null
until a new warning is reported for this Statement
.
clearWarnings
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurs (why?)public int[] executeBatch() throws java.sql.BatchUpdateException
executeBatch
in interface java.sql.Statement
java.sql.BatchUpdateException
- if an error occurs on one statement (the
number of updated rows for the successfully executed
statements can be found in
BatchUpdateException.getUpdateCounts())public void close() throws java.sql.SQLException
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.
close
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurs (why?)public boolean execute(java.lang.String sql) throws java.sql.SQLException
execute
in interface java.sql.Statement
sql
- any SQL statement
java.sql.SQLException
- if an error occurspublic java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLException
executeQuery
in interface java.sql.Statement
sql
- typically a static SQL SELECT
statement
java.sql.SQLException
- if a database access error occursprotected java.sql.ResultSet executeQuery(java.lang.String sqlSkeleton, java.lang.String sqlQuery) throws java.sql.SQLException
sqlSkeleton
- the SQL request squeleton or nullsqlQuery
- typically a static SQL SELECT
statement that
is already trimed
java.sql.SQLException
- if a database access error occurs or if this
statement is closedpublic int executeUpdate(java.lang.String sql) throws java.sql.SQLException
executeUpdate
in interface java.sql.Statement
sql
- a SQL statement
java.sql.SQLException
- if a database access error occursprotected int executeUpdateWithSkeleton(java.lang.String sqlSkeleton, java.lang.String sqlQuery) throws java.sql.SQLException
sqlSkeleton
- the SQL request squeleton or nullsqlQuery
- a static SQL statement that is already trimed
java.sql.SQLException
- if a database access error occurs or if this
statement is closedpublic java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface java.sql.Statement
java.sql.Connection
object
java.sql.SQLException
- neverpublic int getFetchDirection() throws java.sql.SQLException
getFetchDirection
in interface java.sql.Statement
java.sql.SQLException
Statement.getFetchDirection()
public int getFetchSize() throws java.sql.SQLException
getFetchSize
in interface java.sql.Statement
java.sql.SQLException
Statement.getFetchSize()
public int getMaxFieldSize() throws java.sql.SQLException
BINARY
,
VARBINARY
,LONGVARBINARY
,CHAR
,
VARCHAR
and LONGVARCHAR
columns. If the limit
is exceeded, the excess data is silently discarded.
Note: We don't do anything with this value yet.
getMaxFieldSize
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurspublic int getMaxRows() throws java.sql.SQLException
ResultSet
can contain. If the limit is exceeded, the excess
rows are silently dropped.
getMaxRows
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurspublic boolean getMoreResults() throws java.sql.SQLException
getMoreResults
in interface java.sql.Statement
java.sql.SQLException
- if an error occurspublic int getQueryTimeout() throws java.sql.SQLException
SQLException
is thrown.
getQueryTimeout
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurspublic java.sql.ResultSet getResultSet() throws java.sql.SQLException
ResultSet
.
getResultSet
in interface java.sql.Statement
java.sql.SQLException
- neverpublic int getResultSetConcurrency() throws java.sql.SQLException
ResultSet
.
getResultSetConcurrency
in interface java.sql.Statement
CONCUR_READ_ONLY
or CONCUR_UPDATABLE
java.sql.SQLException
- neverpublic int getResultSetType() throws java.sql.SQLException
ResultSet
.
getResultSetType
in interface java.sql.Statement
TYPE_FORWARD_ONLY
or
TYPE_SCROLL_INSENSITIVE
java.sql.SQLException
- neverpublic int getUpdateCount() throws java.sql.SQLException
ResultSet
or there are no more results, -1 is returned. It
should only be called once per result.
getUpdateCount
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurspublic java.sql.SQLWarning getWarnings() throws java.sql.SQLException
Statement
warnings will be chained to this SQLWarning.
The Warning chain is automatically cleared each time a statement is (re)executed.
Note: if you are processing a ResultSet
then any
warnings associated with ResultSet
reads will be chained on
the ResultSet
object.
getWarnings
in interface java.sql.Statement
java.sql.SQLException
- if a database access error occurspublic void setCursorName(java.lang.String name) throws java.sql.SQLException
setCursorName
in interface java.sql.Statement
name
- the new cursor name
java.sql.SQLException
- not supportedpublic void setEscapeProcessing(boolean enable) throws java.sql.SQLException
setEscapeProcessing
in interface java.sql.Statement
enable
- true to enable; false to disable
java.sql.SQLException
- if a database access error occurspublic void setFetchDirection(int direction) throws java.sql.SQLException
setFetchDirection
in interface java.sql.Statement
java.sql.SQLException
Statement.setFetchDirection(int)
public void setFetchSize(int rows) throws java.sql.SQLException
setFetchSize
in interface java.sql.Statement
rows
- number of rows that should be fetched from the database
java.sql.SQLException
- if a database access error occurs or the condition
0 <= size <= this.getMaxRows is not satisfiedpublic void setMaxFieldSize(int max) throws java.sql.SQLException
maxFieldSize
.
setMaxFieldSize
in interface java.sql.Statement
max
- the new max column size limit; 0 means unlimited
java.sql.SQLException
- if a database access error occurs or the condition
max >= 0 is not satisfiedpublic void setMaxRows(int max) throws java.sql.SQLException
ResultSet
can
contain.
setMaxRows
in interface java.sql.Statement
max
- the new max rows limit; 0 means unlimited
java.sql.SQLException
- if a database access error occurs or the condition
max >= 0 is not satisfiedpublic void setQueryTimeout(int seconds) throws java.sql.SQLException
Statement
object to execute.
setQueryTimeout
in interface java.sql.Statement
seconds
- the new query timeout limit in seconds; 0 means no timeout
java.sql.SQLException
- if a database access error occurs or the condition
seconds >= 0 is not satisfiedpublic void setResultSetConcurrency(int value) throws java.sql.SQLException
value
- an int
value
java.sql.SQLException
- if an error occurspublic void setResultSetType(int value) throws java.sql.SQLException
value
- an int
value
java.sql.SQLException
- if an error occurspublic boolean getMoreResults(int current) throws java.sql.SQLException
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.
There are no more results when the following is true
:
(!getMoreResults() && (getUpdateCount() == -1)
getMoreResults
in interface java.sql.Statement
current
- one of the following Statement
constants
indicating what should happen to current ResultSet
objects obtained using the method
getResultSetCLOSE_CURRENT_RESULT
,
KEEP_CURRENT_RESULT
, or CLOSE_ALL_RESULTS
true
if the next result is a ResultSet
object; false
if it is an update count or there are
no more results
java.sql.SQLException
- if a database access error occursexecute(String)
public java.sql.ResultSet getGeneratedKeys() throws java.sql.SQLException
Statement
object. If this Statement
object
did not generate any keys, an empty ResultSet
object is
returned.
getGeneratedKeys
in interface java.sql.Statement
ResultSet
object containing the auto-generated
key(s) generated by the execution of this Statement
object
java.sql.SQLException
- if a database access error occurspublic int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
Statement
object should be made available for retrieval.
executeUpdate
in interface java.sql.Statement
sql
- must be an SQL INSERT
,UPDATE
or
DELETE
statement or an SQL statement that returns
nothingautoGeneratedKeys
- 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
INSERT
,
UPDATE
or DELETE
statements, or
0
for SQL statements that return nothing
java.sql.SQLException
- if a database access error occurs, the given SQL
statement returns a ResultSet
object, or the
given constant is not one of those allowedpublic int executeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
INSERT
statement.
executeUpdate
in interface java.sql.Statement
sql
- an SQL INSERT
,UPDATE
or
DELETE
statement or an SQL statement that returns
nothing, such as an SQL DDL statementcolumnIndexes
- an array of column indexes indicating the columns that
should be returned from the inserted row
INSERT
,
UPDATE
, or DELETE
statements, or 0
for SQL statements that return nothing
java.sql.SQLException
- if a database access error occurs or the SQL
statement returns a ResultSet
objectpublic int executeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
INSERT
statement.
executeUpdate
in interface java.sql.Statement
sql
- an SQL INSERT
,UPDATE
or
DELETE
statement or an SQL statement that returns
nothingcolumnNames
- an array of the names of the columns that should be
returned from the inserted row
INSERT
,
UPDATE
, or DELETE
statements, or 0
for SQL statements that return nothing
java.sql.SQLException
- if a database access error occurspublic boolean execute(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
INSERT
statement.
In some (uncommon) situations, a single SQL statement may return multiple result sets and/or update counts. Normally you can ignore this unless you are (1) executing a stored procedure that you know may return multiple results or (2) you are dynamically executing an unknown SQL string.
The execute
method executes an SQL statement and indicates
the form of the first result. You must then use the methods
getResultSet
or getUpdateCount
to retrieve
the result, and getMoreResults
to move to any subsequent
result(s).
execute
in interface java.sql.Statement
sql
- any SQL statementautoGeneratedKeys
- 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
true
if the first result is a ResultSet
object; false
if it is an update count or there are
no results
java.sql.SQLException
- if a database access error occursgetResultSet()
,
getUpdateCount()
,
getMoreResults()
,
getGeneratedKeys()
public boolean execute(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
INSERT
statement.
Under some (uncommon) situations, a single SQL statement may return multiple result sets and/or update counts. Normally you can ignore this unless you are (1) executing a stored procedure that you know may return multiple results or (2) you are dynamically executing an unknown SQL string.
The execute
method executes an SQL statement and indicates
the form of the first result. You must then use the methods
getResultSet
or getUpdateCount
to retrieve
the result, and getMoreResults
to move to any subsequent
result(s).
execute
in interface java.sql.Statement
sql
- any SQL statementcolumnIndexes
- 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
true
if the first result is a ResultSet
object; false
if it is an update count or there are
no results
java.sql.SQLException
- if a database access error occursgetResultSet()
,
getUpdateCount()
,
getMoreResults()
public boolean execute(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
INSERT
statement.
In some (uncommon) situations, a single SQL statement may return multiple result sets and/or update counts. Normally you can ignore this unless you are (1) executing a stored procedure that you know may return multiple results or (2) you are dynamically executing an unknown SQL string.
The execute
method executes an SQL statement and indicates
the form of the first result. You must then use the methods
getResultSet
or getUpdateCount
to retrieve
the result, and getMoreResults
to move to any subsequent
result(s).
execute
in interface java.sql.Statement
sql
- any SQL statementcolumnNames
- 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
true
if the next result is a ResultSet
object; false
if it is an update count or there are
no more results
java.sql.SQLException
- if a database access error occursgetResultSet()
,
getUpdateCount()
,
getMoreResults()
,
getGeneratedKeys()
public int getResultSetHoldability() throws java.sql.SQLException
ResultSet
objects
generated by this Statement
object.
getResultSetHoldability
in interface java.sql.Statement
ResultSet.HOLD_CURSORS_OVER_COMMIT
or
ResultSet.CLOSE_CURSORS_AT_COMMIT
java.sql.SQLException
- if a database access error occursprivate boolean isClosed()
true
if this statement is closed
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |