public class DBStatement extends Object implements Statement
You should not need to create a DBStatement as they are managed by the DBDatabase internally.
DBStatement simplifies the JDBC interface by managing the connection and statement simultaneously. When the statement is closed so is the connection ensuring minimalist usage of the database.
Mostly this is a thin wrapper around DBDatabase, Connection, and Statement objects
Support DBvolution at Patreon
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO| Constructor and Description |
|---|
DBStatement(DBDatabase db,
Connection connection)
Creates a statement object for the given DBDatabase and Connection.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addBatch(String string)
Adds the given SQL command to the current list of commands for this
Statement object.
|
void |
cancel()
Cancels this Statement object if both the DBMS and driver support aborting
an SQL statement.
|
void |
clearBatch()
Empties this Statement object's current list of SQL commands.
|
void |
clearWarnings()
Clears all the warnings reported on this Statement object.
|
void |
close()
Closes the Statement and the Connection.
|
void |
closeOnCompletion()
Unsupported.
|
boolean |
execute(String sql)
Executes the given SQL statement, which may return multiple results.
|
boolean |
execute(String string,
int i)
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(String string,
int[] ints)
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(String string,
String[] strings)
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()
Submits a batch of commands to the database for execution and if all
commands execute successfully, returns an array of update counts.
|
ResultSet |
executeQuery(String string)
Executes the given SQL statement, which returns a single ResultSet object.
|
int |
executeUpdate(String string)
Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE
statement or an SQL statement that returns nothing, such as an SQL DDL
statement.
|
int |
executeUpdate(String string,
int i)
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(String string,
int[] ints)
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(String string,
String[] strings)
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.
|
boolean |
getBatchHasEntries()
Indicates that a batch has been added.
|
Connection |
getConnection()
Retrieves the Connection object that produced this Statement object.
|
int |
getFetchDirection()
Retrieves the direction for fetching rows from database tables that is the
default for result sets generated from this Statement object.
|
int |
getFetchSize()
Retrieves the number of result set rows that is the default fetch size for
ResultSet objects generated from this Statement object.
|
ResultSet |
getGeneratedKeys()
Retrieves any auto-generated keys created as a result of executing this
Statement object.
|
protected Statement |
getInternalStatement()
Support DBvolution at Patreon |
int |
getMaxFieldSize()
Retrieves the maximum number of bytes that can be returned for character
and binary column values in a ResultSet object produced by this Statement
object.
|
int |
getMaxRows()
Retrieves the maximum number of rows that a ResultSet object produced by
this Statement object can contain.
|
boolean |
getMoreResults()
Moves to this Statement object's next result, returns true if it is a
ResultSet object, and implicitly closes any current ResultSet object(s)
obtained with the method getResultSet.
|
boolean |
getMoreResults(int i)
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()
Retrieves the number of seconds the driver will wait for a Statement object
to execute.
|
ResultSet |
getResultSet()
Retrieves the current result as a ResultSet object.
|
int |
getResultSetConcurrency()
Retrieves the result set concurrency for ResultSet objects generated by
this Statement object.
|
int |
getResultSetHoldability()
Retrieves the result set holdability for ResultSet objects generated by
this Statement object.
|
int |
getResultSetType()
Retrieves the result set type for ResultSet objects generated by this
Statement object.
|
int |
getUpdateCount()
Retrieves the current result as an update count; if the result is a
ResultSet object or there are no more results, -1 is returned.
|
SQLWarning |
getWarnings()
Retrieves the first warning reported by calls on this Statement object.
|
boolean |
isClosed()
Retrieves whether this Statement object has been closed.
|
boolean |
isCloseOnCompletion()
Unsupported.
|
boolean |
isPoolable()
Returns a value indicating whether the Statement is poolable or not.
|
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.
|
protected void |
replaceBrokenConnection()
Discards the current connection, replaces it, and creates a new statement.
|
void |
setCursorName(String string)
Sets the SQL cursor name to the given String, which will be used by
subsequent Statement object execute methods.
|
void |
setEscapeProcessing(boolean bln)
Sets escape processing on or off.
|
void |
setFetchDirection(int i)
Gives the driver a hint as to the direction in which rows will be processed
in ResultSet objects created using this Statement object.
|
void |
setFetchSize(int i)
Gives the JDBC driver a hint as to the number of rows that should be
fetched from the database when more rows are needed for ResultSet objects
generated by this Statement.
|
protected void |
setInternalStatement(Statement realStatement) |
void |
setMaxFieldSize(int i)
Sets the limit for the maximum number of bytes that can be returned for
character and binary column values in a ResultSet object produced by this
Statement object.
|
void |
setMaxRows(int i)
Sets the limit for the maximum number of rows that any ResultSet object
generated by this Statement object can contain to the given number.
|
void |
setPoolable(boolean bln)
Requests that a Statement be pooled or not pooled.
|
void |
setQueryTimeout(int i)
Sets the number of seconds the driver will wait for a Statement object to
execute to the given number of seconds.
|
<T> T |
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.
|
public DBStatement(DBDatabase db, Connection connection) throws SQLException
db - the target databaseconnection - the connection to the databaseSQLException - datbase exceptionspublic ResultSet executeQuery(String string) throws SQLException
executeQuery in interface Statementstring - SQL
Support DBvolution at Patreon
SQLException - database exceptionspublic int executeUpdate(String string) throws SQLException
executeUpdate in interface Statementstring - string
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic void close()
throws SQLException
Also informs the DBDatabase that there is one less connection to the database. 1 Database exceptions may be thrown
close in interface AutoCloseableclose in interface StatementSQLException - java.sql.SQLExceptionpublic int getMaxFieldSize()
throws SQLException
Support DBvolution at Patreon
getMaxFieldSize in interface StatementSQLException - java.sql.SQLExceptionpublic void setMaxFieldSize(int i)
throws SQLException
setMaxFieldSize in interface Statementi - iSQLException - java.sql.SQLExceptionpublic int getMaxRows()
throws SQLException
Support DBvolution at Patreon
getMaxRows in interface StatementResultSet
object produced by this Statement object; zero means there is
no limit 1 Database exceptions may be thrownSQLException - java.sql.SQLExceptionpublic void setMaxRows(int i)
throws SQLException
setMaxRows in interface Statementi - iSQLException - java.sql.SQLExceptionpublic void setEscapeProcessing(boolean bln)
throws SQLException
setEscapeProcessing in interface Statementbln - blnSQLException - java.sql.SQLExceptionpublic int getQueryTimeout()
throws SQLException
Support DBvolution at Patreon
getQueryTimeout in interface StatementSQLException - java.sql.SQLExceptionpublic void setQueryTimeout(int i)
throws SQLException
setQueryTimeout in interface Statementi - iSQLException - java.sql.SQLExceptionpublic void cancel()
throws SQLException
cancel in interface StatementSQLExceptionprotected void replaceBrokenConnection()
throws SQLException,
UnableToCreateDatabaseConnectionException,
UnableToFindJDBCDriver
Call this after canceling or closing a statement for a database that close
the connection with the statement. Use DBDefinition.willCloseConnectionOnStatementCancel() to detect this situation.
SQLException - exceptions from connecting to the database and
creating a Statement.UnableToCreateDatabaseConnectionException - may be thrown if there is
an issue with connecting.UnableToFindJDBCDriver - may be thrown if the JDBCDriver is not on
the class path. DBvolution includes several JDBCDrivers already but Oracle
and MS SQLserver, in particular, need to be added to the path if you wish
to work with those databases.public SQLWarning getWarnings() throws SQLException
The warning chain is automatically cleared each time a statement is (re)executed. This method may not be called on a closed Statement object; doing so will cause an SQLException to be thrown.
Support DBvolution at Patreon
getWarnings in interface StatementSQLWarning object or null if
there are no warnings 1 Database exceptions may be thrownSQLException - java.sql.SQLExceptionpublic void clearWarnings()
throws SQLException
clearWarnings in interface StatementSQLException - java.sql.SQLExceptionpublic void setCursorName(String string) throws SQLException
This name can then be used in SQL positioned update or delete statements to identify the current row in the ResultSet object generated by this statement. If the database does not 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 have the form SELECT FOR UPDATE. If FOR UPDATE is not present, positioned updates may fail. 1 Database exceptions may be thrown
setCursorName in interface Statementstring - stringSQLException - java.sql.SQLExceptionpublic boolean execute(String sql) throws SQLException
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 Statementsql - string
Support DBvolution at Patreon
TRUE if the first result is a ResultSet
object; FALSE if it is an update count or there are no results
1 Database exceptions may be thrownSQLException - java.sql.SQLExceptionpublic ResultSet getResultSet() throws SQLException
This method should be called only once per result.
Support DBvolution at Patreon
getResultSet in interface StatementResultSet object or
null if the result is an update count or there are no more
results 1 Database exceptions may be thrownSQLException - java.sql.SQLExceptionpublic int getUpdateCount()
throws SQLException
This method should be called only once per result.
Support DBvolution at Patreon
getUpdateCount in interface StatementResultSet object or there are no more results. 1 Database
exceptions may be thrownSQLException - java.sql.SQLExceptionpublic boolean getMoreResults()
throws SQLException
There are no more results when the following is true:
// stmt is a Statement object ((stmt.getMoreResults() == false) &&
(stmt.getUpdateCount() == -1))
Support DBvolution at Patreon
getMoreResults in interface StatementSQLException - java.sql.SQLExceptionpublic void setFetchDirection(int i)
throws SQLException
The default value is ResultSet.FETCH_FORWARD. 1 Database exceptions may be thrown
setFetchDirection in interface Statementi - iSQLException - java.sql.SQLExceptionpublic int getFetchDirection()
throws SQLException
If this Statement object has not set a fetch direction by calling the method setFetchDirection, the return value is implementation-specific.
Support DBvolution at Patreon
getFetchDirection in interface StatementSQLException - java.sql.SQLExceptionpublic void setFetchSize(int i)
throws SQLException
If the value specified is zero, then the hint is ignored. The default value is zero. 1 Database exceptions may be thrown
setFetchSize in interface Statementi - iSQLException - java.sql.SQLExceptionpublic int getFetchSize()
throws SQLException
If this Statement object has not set a fetch size by calling the method setFetchSize, the return value is implementation-specific.
Support DBvolution at Patreon
getFetchSize in interface StatementSQLException - java.sql.SQLExceptionpublic int getResultSetConcurrency()
throws SQLException
Support DBvolution at Patreon
getResultSetConcurrency in interface StatementSQLException - java.sql.SQLExceptionpublic int getResultSetType()
throws SQLException
Support DBvolution at Patreon
getResultSetType in interface StatementSQLException - java.sql.SQLExceptionpublic void addBatch(String string) throws SQLException
addBatch in interface Statementstring - stringSQLException - java.sql.SQLExceptionpublic void clearBatch()
throws SQLException
clearBatch in interface StatementSQLException - java.sql.SQLExceptionpublic int[] executeBatch()
throws SQLException
The int elements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch. The elements in the array returned by the method executeBatch may be one of the following:
If one of the commands in a batch update fails to execute properly, this method throws a BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands. If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getUpdateCounts will contain as many elements as there are commands in the batch, and at least one of the elements will be a value of EXECUTE_FAILED.
The possible implementations and return values have been modified in the Java 2 SDK, Standard Edition, version 1.3 to accommodate the option of continuing to process commands in a batch update after a BatchUpdateException object has been thrown.
Support DBvolution at Patreon
executeBatch in interface StatementSQLException - java.sql.SQLExceptionpublic Connection getConnection() throws SQLException
Support DBvolution at Patreon
getConnection in interface StatementSQLException - java.sql.SQLExceptionpublic boolean getMoreResults(int i)
throws SQLException
There are no more results when the following is true:
(statement.getMoreResults(current) == false)
&& (statement.getUpdateCount() == -1))
getMoreResults in interface Statementi - i
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic ResultSet getGeneratedKeys() throws SQLException
If this Statement object did not generate any keys, an empty ResultSet object is returned.
Support DBvolution at Patreon
getGeneratedKeys in interface StatementSQLException - java.sql.SQLExceptionpublic int executeUpdate(String string, int i) throws SQLException
The driver will ignore the flag if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).
executeUpdate in interface Statementstring - stringi - i
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic int executeUpdate(String string, int[] ints) throws SQLException
This array contains the indexes of the columns in the target table that contain the auto-generated keys that should be made available. The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).
executeUpdate in interface Statementstring - stringints - ints
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic int executeUpdate(String string, String[] strings) throws SQLException
This array contains the names of the columns in the target table that contain the auto-generated keys that should be made available. The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific).
executeUpdate in interface Statementstring - stringstrings - strings
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic boolean execute(String string, int i) throws SQLException
The driver will ignore this signal if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific). 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 Statementstring - stringi - i
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic boolean execute(String string, int[] ints) throws SQLException
This array contains the indexes of the columns in the target table that contain the auto-generated keys that should be made available. The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific). 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 Statementstring - stringints - ints
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic boolean execute(String string, String[] strings) throws SQLException
This array contains the names of the columns in the target table that contain the auto-generated keys that should be made available. The driver will ignore the array if the SQL statement is not an INSERT statement, or an SQL statement able to return auto-generated keys (the list of such statements is vendor-specific). 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 Statementstring - stringstrings - strings
Support DBvolution at Patreon
SQLException - java.sql.SQLExceptionpublic int getResultSetHoldability()
throws SQLException
Support DBvolution at Patreon
getResultSetHoldability in interface StatementSQLException - java.sql.SQLExceptionpublic boolean isClosed()
throws SQLException
Support DBvolution at Patreon
isClosed in interface StatementSQLException - java.sql.SQLExceptionpublic void setPoolable(boolean bln)
throws SQLException
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 not poolable when created, and a PreparedStatement and CallableStatement are poolable when created. 1 Database exceptions may be thrown
setPoolable in interface Statementbln - blnSQLException - java.sql.SQLExceptionpublic boolean isPoolable()
throws SQLException
Support DBvolution at Patreon
isPoolable in interface StatementSQLException - java.sql.SQLExceptionpublic <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 WrapperT - the required interface.
Support DBvolution at Patreon
iface - A Class defining an interface that the result must implement.SQLException - java.sql.SQLExceptionpublic 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 Wrapperiface - a Class defining an interface.
Support DBvolution at Patreon
SQLException - if an error occurs while determining whether
this is a wrapper for an object with the given interface.public boolean getBatchHasEntries()
Support DBvolution at Patreon
public void closeOnCompletion()
throws SQLException
closeOnCompletion in interface StatementSQLException - java.sql.SQLExceptionpublic boolean isCloseOnCompletion()
throws SQLException
Support DBvolution at Patreon
isCloseOnCompletion in interface StatementSQLException - java.sql.SQLExceptionprotected Statement getInternalStatement()
Support DBvolution at Patreon
protected void setInternalStatement(Statement realStatement)
realStatement - the internalStatement to setCopyright © 2018. All Rights Reserved.