|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.as400.access.AS400JDBCStatement
public class AS400JDBCStatement
The AS400JDBCStatement class provides a mechanism for executing static SQL statements. Use Connection.createStatement() to create new Statement objects.
Only one result set per statement can be open at any point in time. Therefore, if an application needs to read from multiple result sets, then each must be generated by a different statement.
AS400JDBCStatements are thread-safe.
Note that the connection keeps a reference to each statement that it creates. This means that statements will not get garbage collected until the connection gets garbage collected. It is best to explicitly close statements rather than counting on garbage collection.
Field Summary |
---|
Fields inherited from interface java.sql.Statement |
---|
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, SUCCESS_NO_INFO |
Method Summary | ||
---|---|---|
void |
addBatch(String sql)
Adds an SQL statement to the current batch of SQL statements. |
|
void |
cancel()
Cancels the statement. |
|
void |
clearBatch()
Clears the current batch of SQL statements. |
|
void |
clearWarnings()
Clears all warnings that have been reported for the statement. |
|
void |
close()
Releases the statement's resources immediately instead of waiting for them to be automatically released. |
|
boolean |
execute(String sql)
Runs an SQL statement that may return multiple result sets. |
|
boolean |
execute(String sql,
int autoGeneratedKeys)
Runs an SQL statement that may return multiple result sets and makes any auto-generated keys available for retrieval using Statement.getGeneratedKeys(). |
|
boolean |
execute(String sql,
int[] columnIndexes)
Runs an SQL statement that may return multiple result sets and makes any auto-generated keys for the columns indicated in the given array available for retrieval using Statement.getGeneratedKeys(). |
|
boolean |
execute(String sql,
String[] columnNames)
Runs an SQL statement that may return multiple result sets and makes any auto-generated keys for the columns indicated in the given array available for retrieval using Statement.getGeneratedKeys(). |
|
int[] |
executeBatch()
Runs the batch of SQL statements. |
|
ResultSet |
executeQuery(String sql)
Runs an SQL statement that returns a single result set. |
|
int |
executeUpdate(String sql)
Runs an SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not return a result set. |
|
int |
executeUpdate(String sql,
int autoGeneratedKeys)
Runs an SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not return a result set and makes any auto-generated keys available for retrieval using Statement.getGeneratedKeys(). |
|
int |
executeUpdate(String sql,
int[] columnIndexes)
Runs an SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not return a result set and makes any auto-generated keys for the columns indicated in the given array available for retrieval using Statement.getGeneratedKeys(). |
|
int |
executeUpdate(String sql,
String[] columnNames)
Runs an SQL INSERT, UPDATE, or DELETE statement, or any SQL statement that does not return a result set and makes any auto-generated keys for the columns indicated in the given array available for retrieval using Statement.getGeneratedKeys(). |
|
protected void |
finalize()
Closes the statement if not explicitly closed by the caller. |
|
Connection |
getConnection()
Returns the connection for this statement. |
|
int |
getFetchDirection()
Returns the fetch direction. |
|
int |
getFetchSize()
Returns the fetch size. |
|
ResultSet |
getGeneratedKeys()
Retrieves any auto-generated keys created as a result of executing this Statement object. |
|
int |
getMaxFieldSize()
Returns the maximum field size limit for the statement. |
|
int |
getMaxRows()
Returns the maximum rows limit for the statement. |
|
boolean |
getMoreResults()
Returns the next result set. |
|
boolean |
getMoreResults(int current)
Returns the next result set. |
|
int |
getPositionOfSyntaxError()
Will return the value of the last syntax error that came back from the IBM i system. |
|
int |
getQueryTimeout()
Returns the query timeout limit for this statement. |
|
ResultSet |
getResultSet()
Returns the current result set. |
|
int |
getResultSetConcurrency()
Returns the result set concurrency to be used for this statement. |
|
int |
getResultSetHoldability()
Returns the result set cursor holdability to be used for this statement. |
|
int |
getResultSetType()
Returns the result set type to be used for this statement. |
|
int |
getUpdateCount()
Returns the current update count. |
|
protected String[] |
getValidWrappedList()
|
|
SQLWarning |
getWarnings()
Returns the first warning reported for the statement. |
|
boolean |
isClosed()
Indicates if the statement is closed. |
|
boolean |
isPoolable()
Returns the value of the statements poolable hint, indicating whether pooling of the statement is requested. |
|
boolean |
isWrapperFor(Class<?> iface)
Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. |
|
void |
setCursorName(String cursorName)
Sets the SQL cursor name that will be used by the statement. |
|
void |
setEscapeProcessing(boolean escapeProcessing)
Sets the escape processing mode. |
|
void |
setFetchDirection(int fetchDirection)
Sets the direction in which the rows in a result set will be processed. |
|
void |
setFetchSize(int fetchSize)
Sets the number of rows to be fetched from the database when more rows are needed. |
|
void |
setMaxFieldSize(int maxFieldSize)
Sets the maximum field size limit. |
|
void |
setMaxRows(int maxRows)
Sets the maximum rows limit. |
|
void |
setPoolable(boolean poolable)
Requests that a Statement be pooled or not pooled. |
|
void |
setQueryTimeout(int queryTimeout)
Sets the query timeout limit. |
|
String |
toString()
Returns the statement name. |
|
|
unwrap(Class<T> iface)
Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.sql.Wrapper |
---|
isWrapperFor, unwrap |
Method Detail |
---|
public void addBatch(String sql) throws SQLException
addBatch
in interface Statement
sql
- The SQL statement to be added to the current batch.
This can be any SQL statement that does not return
a result set.
SQLException
- If the statement is not open or
the SQL statement contains a syntax
error.public void cancel() throws SQLException
cancel
in interface Statement
SQLException
- If the statement is not open or
an error occurs.public void clearBatch() throws SQLException
clearBatch
in interface Statement
SQLException
- If the statement is not open.public void clearWarnings() throws SQLException
clearWarnings
in interface Statement
SQLException
- If an error occurs.public void close() throws SQLException
close
in interface Statement
SQLException
- If an error occurs.public boolean execute(String sql) throws SQLException
Under some situations, a single SQL statement may return multiple result sets, an update count, or both. This might occur when executing a stored procedure that returns multiple result sets or when dynamically executing an unknown SQL string.
Use getMoreResults(), getResultSet(), and getUpdateCount() to navigate through multiple result sets, an update count, or both.
execute
in interface Statement
sql
- The SQL statement.
SQLException
- If the statement is not open,
the SQL statement contains a syntax
error, the query timeout limit is
exceeded, or an error occurs.public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
Under some situations, a single SQL statement may return multiple result sets, an update count, or both. This might occur when executing a stored procedure that returns multiple result sets or when dynamically executing an unknown SQL string.
Use getMoreResults(), getResultSet(), and getUpdateCount() to navigate through multiple result sets, an update count, or both.
This method requires OS/400 V5R2 or IBM i. If connecting to OS/400 V5R1 or earlier, an exception will be thrown.
execute
in interface Statement
sql
- The SQL statement.autoGeneratedKeys
- Indicates whether auto-generated keys should be made available for
retrieval. Valid values are Statement.RETURN_GENERATED_KEYS and
Statement.NO_GENERATED_KEYS.
SQLException
- If the statement is not open,
the SQL statement contains a syntax
error, the query timeout limit is
exceeded, the value for autoGeneratedKeys is
not a valid value, if connecting to OS/400 V5R1
or earlier, an error occurs.public boolean execute(String sql, int[] columnIndexes) throws SQLException
Under some situations, a single SQL statement may return multiple result sets, an update count, or both. This might occur when executing a stored procedure that returns multiple result sets or when dynamically executing an unknown SQL string.
Use getMoreResults(), getResultSet(), and getUpdateCount() to navigate through multiple result sets, an update count, or both.
This method is not supported when connecting to IBM i V5R4 or earlier systems.
execute
in interface Statement
sql
- The SQL statement.columnIndexes
- Indicates that auto-generated keys for the indicated
columns should be made available for retrieval.
SQLException
- - If connecting to IBM i V5R4 or earlier systems,
if the statement is not open,
the SQL statement contains a syntax
error, the query timeout limit is
exceeded, the value for columnIndexes is
not a valid value, or an error occurs.public boolean execute(String sql, String[] columnNames) throws SQLException
Under some situations, a single SQL statement may return multiple result sets, an update count, or both. This might occur when executing a stored procedure that returns multiple result sets or when dynamically executing an unknown SQL string.
Use getMoreResults(), getResultSet(), and getUpdateCount() to navigate through multiple result sets, an update count, or both.
This method is not supported when connecting to IBM i V5R4 or earlier systems.
execute
in interface Statement
sql
- The SQL statement.columnNames
- Indicates that auto-generated keys for the indicated
columns should be made available for retrieval.
SQLException
- - If connecting to IBM i V5R4 or earlier systems,
if the statement is not open,
the SQL statement contains a syntax
error, the query timeout limit is
exceeded, the value for columnNames is
not a valid value, or an error occurs.public int[] executeBatch() throws SQLException
When batch updates are run, autocommit should usually be turned off. This allows the caller to decide whether or not to commit the transaction in the event that an error occurs and some of the SQL statements in a batch fail to run.
executeBatch
in interface Statement
SQLException
- If the statement is not open,
an SQL statement contains a syntax
error, the query timeout limit is
exceeded, an SQL statement returns
a result set, or an error occurs.public ResultSet executeQuery(String sql) throws SQLException
executeQuery
in interface Statement
sql
- The SQL statement.
SQLException
- If the statement is not open,
the SQL statement contains a syntax
error, no result set is returned by the
database, the query timeout limit is
exceeded, or an error occurs.public int executeUpdate(String sql) throws SQLException
executeUpdate
in interface Statement
sql
- The SQL statement.
SQLException
- If the statement is not open,
the SQL statement contains a syntax
error, the query timeout limit is
exceeded, the statement returns
a result set, or an error occurs.public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
This method requires OS/400 V5R2 or or IBM i. If connecting to OS/400 V5R1 or earlier, an exception will be thrown.
executeUpdate
in interface Statement
sql
- The SQL statement.
SQLException
- If the statement is not open,
the SQL statement contains a syntax
error, the query timeout limit is
exceeded, the statement returns
a result set, the value for autoGeneratedKeys is
not a valid value, if connecting to OS/400 V5R1
or earlier, an error occurs.public int executeUpdate(String sql, int[] columnIndexes) throws SQLException
This method is not supported when connecting to IBM i V5R4 or earlier systems.
executeUpdate
in interface Statement
sql
- The SQL statement.columnIndexes
- The indexes of columns for which auto-generated keys should be made
available for retrieval.
SQLException
- If connection to IBM i V5R4 or earlier systems,
the statement is not open,
the SQL statement contains a syntax
error, the query timeout limit is
exceeded, the statement returns
a result set, the value for autoGeneratedKeys is
not a valid value or an error occurs.public int executeUpdate(String sql, String[] columnNames) throws SQLException
This method is not supported when connecting to IBM i V5R4 or earlier systems.
executeUpdate
in interface Statement
sql
- The SQL statement.columnNames
- The column names for which auto-generated keys should be made
available for retrieval.
SQLException
- If connection to IBM i V5R4 or earlier systems,
the statement is not open,
the SQL statement contains a syntax
error, the query timeout limit is
exceeded, the statement returns
a result set, the value for autoGeneratedKeys is
not a valid value or an error occurs.protected void finalize() throws Throwable
finalize
in class Object
Throwable
- If an error occurs.public Connection getConnection() throws SQLException
getConnection
in interface Statement
SQLException
- If an error occurs.public int getFetchDirection() throws SQLException
getFetchDirection
in interface Statement
SQLException
- If the statement is not open.public int getFetchSize() throws SQLException
getFetchSize
in interface Statement
SQLException
- If the statement is not open.public ResultSet getGeneratedKeys() throws SQLException
In order for this method to return auto-generated keys, the statement must be executed on a table with an identity column. For more information about identity columns, Go to the IBM i Information Center, and search on the phrase "identity column".
This method requires OS/400 V5R2 or IBM i. If connecting to OS/400 V5R1 or earlier, an exception will be thrown.
This method will return null if the user did not request auto-generated keys during the execute of a Statement or during the prepare of a PreparedStatement. This method will also return null if the application has not executed the statement before calling this method.
This method will return an empty result set if the database did not generate any auto-generated keys when executing the statement.
getGeneratedKeys
in interface Statement
SQLException
- If the statement is not open,
if connecting to OS/400 V5R1 or earlier,
an error occurs.public int getMaxFieldSize() throws SQLException
getMaxFieldSize
in interface Statement
SQLException
- If the statement is not open.public int getMaxRows() throws SQLException
getMaxRows
in interface Statement
SQLException
- If the statement is not open.public boolean getMoreResults() throws SQLException
getMoreResults
in interface Statement
SQLException
- If an error occurs.public boolean getMoreResults(int current) throws SQLException
getMoreResults
in interface Statement
current
- What should happen to current ResultSet objects
obtained using the method getResultSet. Valid values are
CLOSE_CURRENT_RESULT, KEEP_CURRENT_RESULT, and CLOSE_ALL_RESULTS.
SQLException
- if DatabaseMetaData.supportsMultipleOpenResults returns false
and either Statement.KEEP_CURRENT_RESULT or Statement.CLOSE_ALL_RESULTS are
supplied as the argument.public int getPositionOfSyntaxError() throws SQLException
SQLException
- If the statement is not open.public int getQueryTimeout() throws SQLException
getQueryTimeout
in interface Statement
SQLException
- If the statement is not open.public ResultSet getResultSet() throws SQLException
getResultSet
in interface Statement
SQLException
- If the statement is not open.public int getResultSetConcurrency() throws SQLException
getResultSetConcurrency
in interface Statement
SQLException
- If the statement is not open.public int getResultSetHoldability() throws SQLException
getResultSetHoldability
in interface Statement
cursor hold
driver property.SQLException
- If the statement is not open.public int getResultSetType() throws SQLException
getResultSetType
in interface Statement
SQLException
- If the statement is not open.public int getUpdateCount() throws SQLException
getUpdateCount
in interface Statement
SQLException
- If the statement is not open.public SQLWarning getWarnings() throws SQLException
getWarnings
in interface Statement
SQLException
- If an error occurs.public boolean isClosed() throws SQLException
isClosed
in interface Statement
SQLException
public void setCursorName(String cursorName) throws SQLException
The cursor name can be used in SQL positioned UPDATE or DELETE statements to identify the current row in the result set generated by this statement. By definition, SQL positioned UPDATEs or DELETEs must be executed by a different statement than the one that generated the result set being used for positioning.
Cursor names are case sensitive. However, when using a cursor name within other SQL positioned UPDATE or DELETE statements, the cursor name will be uppercased. If you use a cursor name with lowercase characters, you need to enclose it in double quotes when referring to it in other SQL statements.
setCursorName
in interface Statement
cursorName
- The cursor name. If null, a unique
default name will be used.
SQLException
- If the statement is not open,
a result set is open, the cursor
name is not unique within the
connection, or an error occurs.public void setEscapeProcessing(boolean escapeProcessing) throws SQLException
setEscapeProcessing
in interface Statement
escapeProcessing
- true to process escape clauses;
false otherwise. The default
is true.
SQLException
- If the statement is not open.public void setFetchDirection(int fetchDirection) throws SQLException
This setting is not used.
setFetchDirection
in interface Statement
fetchDirection
- The fetch direction for processing rows.
Valid values are:
SQLException
- If the statement is not open,
the result set type is
ResultSet.TYPE_FORWARD_ONLY,
and the input value is not
ResultSet.FETCH_FORWARD,
or the input value is not valid.public void setFetchSize(int fetchSize) throws SQLException
This setting only affects statements that meet the criteria specified in the "block criteria" property. The fetch size is only used if the "block size" property is set to "0".
setFetchSize
in interface Statement
fetchSize
- The number of rows. This must be greater than
or equal to 0 and less than or equal to the
maximum rows limit. The default is zero.
SQLException
- If the statement is not open
or the input value is not valid.public void setMaxFieldSize(int maxFieldSize) throws SQLException
setMaxFieldSize
in interface Statement
maxFieldSize
- The maximum field size limit (in bytes) or
0 for no limit. The default is 0.
SQLException
- If the statement is not open
or the input value is not valid.public void setMaxRows(int maxRows) throws SQLException
setMaxRows
in interface Statement
maxRows
- The maximum rows limit or 0 for no limit.
The default is 0.
SQLException
- If the statement is not open
or the input value is not valid.public void setQueryTimeout(int queryTimeout) throws SQLException
This is implemented using the database query time limit, also known as QQRYTIMLMT. This value specifies the query processing time limit that is compared to the estimated number of elapsed seconds that a query must run. The time limit determines if the database query can start.
Beginning with Version 6 Release 1 of IBM i, you must have *JOBCTL special authority.
setQueryTimeout
in interface Statement
queryTimeout
- The query timeout limit (in seconds)
or 0 for no limit. The default is the job's query timeout limit
value unless this method is explicitly called.
SQLException
- If the statement is not open
or the input value is not valid.public String toString()
toString
in class Object
public void setPoolable(boolean poolable) throws SQLException
Statement
be pooled or not pooled. The value
specified is a hint to the statement pool implementation indicating
whether the applicaiton wants the statement to be pooled. It is up to
the statement pool manager as to whether the hint is used.
The poolable value of a statement is applicable to both internal statement caches implemented by the driver and external statement caches implemented by application servers and other applications.
By default, a Statement
is poolable when it is created.
setPoolable
in interface Statement
poolable
- requests that the statement be pooled if true and
that the statement not be pooled if false
SQLException
- if the Statement
has been closed
public boolean isPoolable() throws SQLException
isPoolable
in interface Statement
SQLException
- if the Statement
has been closed
see java.sql.Statement#setPoolable(boolean) setPoolable(boolean)
protected String[] getValidWrappedList()
public boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor
on the wrapped object. If this does not
implement the interface and is not a wrapper, return false. This method
should be implemented as a low-cost operation compared to
unwrap
so that callers can use this method to avoid
expensive unwrap
calls that may fail. If this method
returns true then calling unwrap
with the same argument
should succeed.
isWrapperFor
in interface Wrapper
iface
- a Class defining an interface.
SQLException
- if an error occurs while determining whether this is a
wrapper for an object with the given interface.public <T> T unwrap(Class<T> iface) throws SQLException
unwrap
recursively on the wrapped object or a
proxy for that result. If the receiver is not a wrapper and does not
implement the interface, then an SQLException
is thrown.
unwrap
in interface Wrapper
iface
- A Class defining an interface that the result must implement.
SQLException
- If no object found that implements the interface
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |