| java.lang.Object net.sourceforge.jtds.jdbc.JtdsStatement
All known Subclasses: net.sourceforge.jtds.jdbc.JtdsPreparedStatement,
JtdsStatement | public class JtdsStatement implements java.sql.Statement(Code) | | jTDS implementation of the java.sql.Statement interface.
NB. As allowed by the JDBC standard and like most other drivers,
this implementation only allows one open result set at a time.
Implementation notes:
I experimented with allowing multiple open result sets as supported
by the origianal jTDS but rejected this approach for the following
reasons:
- It is more difficult to ensure that there are no memory leaks and that
cursors are closed if multiple open sets are allowed.
- The use of one result set allows cursor and non cursor result sets to
be derived from exeuteQuery() or execute() and getResultSet() in the
same way that other drivers do.
In the event of an IO failure the setClosed() method forces this statement
and associated result set to close preventing the propogation of errors.
This class includes a finalize method which increases the chances of the
statement being closed tidly in a pooled environment where the user has
forgotten to explicitly close the statement before it goes out of scope.
See Also: java.sql.Statement See Also: java.sql.Connection.createStatement See Also: java.sql.ResultSet author: Mike Hutchinson version: $Id: JtdsStatement.java,v 1.64 2007/07/12 21:03:23 bheineman Exp $ |
Constructor Summary | |
| JtdsStatement(ConnectionJDBC2 connection, int resultSetType, int resultSetConcurrency) Construct a new Statement object. |
Method Summary | |
public void | addBatch(String sql) | void | addWarning(SQLWarning w) Add an SQLWarning object to the statment warnings list. | protected void | cacheResults() Cache as many results as possible (up to the first
ResultSet ). | public void | cancel() | protected void | checkCursorException(SQLException e) Check that the exception is caused by the failure to open a
cursor and not by a more serious SQL error. | protected void | checkOpen() Check that this statement is still open. | public void | clearBatch() | public void | clearWarnings() | public void | close() | void | closeAllResultSets() Close all result sets. | void | closeCurrentResultSet() Close current result set (if any). | public boolean | execute(String sql) | public boolean | execute(String sql, int autoGeneratedKeys) | public boolean | execute(String sql, int[] columnIndexes) | public boolean | execute(String sql, String[] columnNames) | public int[] | executeBatch() Execute batch of SQL Statements.
The JDBC3 standard says that the behaviour of this method must be
consistent for any DBMS. | protected SQLException | executeMSBatch(int size, int executeSize, ArrayList counts) Execute the SQL batch on a MS server. | public ResultSet | executeQuery(String sql) | protected boolean | executeSQL(String sql, String spName, ParamInfo[] params, boolean returnKeys, boolean update, boolean useCursor) Executes any type of SQL. | protected ResultSet | executeSQLQuery(String sql, String spName, ParamInfo[] params, boolean useCursor) Executes SQL to obtain a result set. | protected SQLException | executeSybaseBatch(int size, int executeSize, ArrayList counts) Execute the SQL batch on a Sybase server.
Sybase needs to have the SQL concatenated into one TDS language packet. | public int | executeUpdate(String sql) | public int | executeUpdate(String sql, int autoGeneratedKeys) | public int | executeUpdate(String sql, int[] columnIndexes) | public int | executeUpdate(String sql, String[] columnNames) | protected void | finalize() Called when this object goes out of scope to close any
ResultSet object and this statement. | public Connection | getConnection() | int | getDefaultFetchSize() Retrieve the default fetch size for this statement. | public int | getFetchDirection() | public int | getFetchSize() | public ResultSet | getGeneratedKeys() | public int | getMaxFieldSize() | public int | getMaxRows() | SQLDiagnostic | getMessages() Get the statement's warnings list. | public boolean | getMoreResults() | public boolean | getMoreResults(int current) | public int | getQueryTimeout() | public ResultSet | getResultSet() | public int | getResultSetConcurrency() | public int | getResultSetHoldability() | public int | getResultSetType() | TdsCore | getTds() Get the Statement's TDS object. | public int | getUpdateCount() | public SQLWarning | getWarnings() | protected void | initialize() Initialize the Statement , by cleaning up all queued and
unprocessed results. | static void | notImplemented(String method) Report that user tried to call a method which has not been implemented. | public void | setCursorName(String name) | public void | setEscapeProcessing(boolean enable) | public void | setFetchDirection(int direction) | public void | setFetchSize(int rows) | public void | setMaxFieldSize(int max) | public void | setMaxRows(int max) | public void | setQueryTimeout(int seconds) | protected boolean | useCursor(boolean returnKeys, String sqlWord) Determines whether a cursor should be used based on the requested result
set type and concurrency, whether a cursor name has been set, the
useCursors connection property has been set, the first
word in the SQL query is either SELECT or EXEC/EXECUTE and no generated
keys are returned. |
BOOLEAN | final static int BOOLEAN(Code) | | |
CLOSE_ALL_RESULTS | final static int CLOSE_ALL_RESULTS(Code) | | |
CLOSE_CURRENT_RESULT | final static int CLOSE_CURRENT_RESULT(Code) | | |
DATALINK | final static int DATALINK(Code) | | |
DEFAULT_FETCH_SIZE | final static int DEFAULT_FETCH_SIZE(Code) | | |
KEEP_CURRENT_RESULT | final static int KEEP_CURRENT_RESULT(Code) | | |
NO_GENERATED_KEYS | final static int NO_GENERATED_KEYS(Code) | | |
RETURN_GENERATED_KEYS | final static int RETURN_GENERATED_KEYS(Code) | | |
batchValues | protected ArrayList batchValues(Code) | | Batched SQL Statement array.
|
closed | protected boolean closed(Code) | | True if this statement is closed.
|
colMetaData | protected ColInfo[] colMetaData(Code) | | The cached column meta data.
|
cursorName | protected String cursorName(Code) | | The cursor name to be used for positioned updates.
|
escapeProcessing | protected boolean escapeProcessing(Code) | | True if SQL statements should be preprocessed.
|
fetchDirection | protected int fetchDirection(Code) | | The fetch direction for result sets.
|
fetchSize | protected int fetchSize(Code) | | The fetch size (default 100, only used by cursor
ResultSet s).
|
genKeyResultSet | protected JtdsResultSet genKeyResultSet(Code) | | Dummy result set for getGeneratedKeys.
|
maxFieldSize | protected int maxFieldSize(Code) | | The maximum field size (not used at present).
|
maxRows | protected int maxRows(Code) | | The maximum number of rows to return (not used at present).
|
openResultSets | protected ArrayList openResultSets(Code) | | List of open result sets.
|
queryTimeout | protected int queryTimeout(Code) | | The read query timeout in seconds
|
resultQueue | final protected LinkedList resultQueue(Code) | | List of queued results (update counts, possibly followed by a
ResultSet ).
|
resultSetConcurrency | protected int resultSetConcurrency(Code) | | The concurrency of result sets created by this statement.
|
resultSetType | protected int resultSetType(Code) | | The type of result sets created by this statement.
|
tds | protected TdsCore tds(Code) | | The TDS object used for server access.
|
JtdsStatement | JtdsStatement(ConnectionJDBC2 connection, int resultSetType, int resultSetConcurrency) throws SQLException(Code) | | Construct a new Statement object.
Parameters: connection - The parent connection. Parameters: resultSetType - The result set type for example TYPE_FORWARD_ONLY. Parameters: resultSetConcurrency - The concurrency for example CONCUR_READ_ONLY. |
addWarning | void addWarning(SQLWarning w)(Code) | | Add an SQLWarning object to the statment warnings list.
Parameters: w - The SQLWarning to add. |
cacheResults | protected void cacheResults() throws SQLException(Code) | | Cache as many results as possible (up to the first
ResultSet ). Called by ResultSet s when the
end is reached.
|
checkCursorException | protected void checkCursorException(SQLException e) throws SQLException(Code) | | Check that the exception is caused by the failure to open a
cursor and not by a more serious SQL error.
Parameters: e - the exception returned by the cursor class throws: SQLException - if exception is not due to a cursor error |
closeAllResultSets | void closeAllResultSets() throws SQLException(Code) | | Close all result sets.
|
closeCurrentResultSet | void closeCurrentResultSet() throws SQLException(Code) | | Close current result set (if any).
|
executeBatch | public int[] executeBatch() throws SQLException, BatchUpdateException(Code) | | Execute batch of SQL Statements.
The JDBC3 standard says that the behaviour of this method must be
consistent for any DBMS. As Sybase (and to a lesser extent SQL Server)
will sometimes continue after a batch execution error, the only way to
comply with the standard is to always return an array of update counts
the same size as the batch list. Slots in the array beyond the last
executed statement are set to EXECUTE_FAILED .
update counts as an int[] |
executeMSBatch | protected SQLException executeMSBatch(int size, int executeSize, ArrayList counts) throws SQLException(Code) | | Execute the SQL batch on a MS server.
Parameters: size - the total size of the batch Parameters: executeSize - the maximum number of statements to send in one request Parameters: counts - the returned update counts chained exceptions linked to a SQLException throws: SQLException - if a serious error occurs during execution |
executeSQL | protected boolean executeSQL(String sql, String spName, ParamInfo[] params, boolean returnKeys, boolean update, boolean useCursor) throws SQLException(Code) | | Executes any type of SQL.
Parameters: sql - the SQL statement to execute Parameters: spName - optional stored procedure name Parameters: params - optional parameters Parameters: returnKeys - whether the statement returns generated keys Parameters: update - whether the caller is JtdsStatement.executeUpdate Parameters: useCursor - whether the requested result set type or concurrencyor connection properties request usage of a cursor true if the first result is a result set throws: SQLException - if an error condition occurs |
executeSQLQuery | protected ResultSet executeSQLQuery(String sql, String spName, ParamInfo[] params, boolean useCursor) throws SQLException(Code) | | Executes SQL to obtain a result set.
Parameters: sql - the SQL statement to execute Parameters: spName - optional stored procedure name Parameters: params - optional parameters Parameters: useCursor - whether a cursor should be created for the SQL the result set generated by the query |
executeSybaseBatch | protected SQLException executeSybaseBatch(int size, int executeSize, ArrayList counts) throws SQLException(Code) | | Execute the SQL batch on a Sybase server.
Sybase needs to have the SQL concatenated into one TDS language packet. This method will be overriden for
PreparedStatements .
Parameters: size - the total size of the batch Parameters: executeSize - the maximum number of statements to send in one request Parameters: counts - the returned update counts chained exceptions linked to a SQLException throws: SQLException - if a serious error occurs during execution |
finalize | protected void finalize() throws Throwable(Code) | | Called when this object goes out of scope to close any
ResultSet object and this statement.
|
getDefaultFetchSize | int getDefaultFetchSize()(Code) | | Retrieve the default fetch size for this statement.
the default fetch size for a new ResultSet |
getMessages | SQLDiagnostic getMessages()(Code) | | Get the statement's warnings list.
The warnings list as a SQLDiagnostic . |
getTds | TdsCore getTds()(Code) | | Get the Statement's TDS object.
The TDS support as a TdsCore Object. |
initialize | protected void initialize() throws SQLException(Code) | | Initialize the Statement , by cleaning up all queued and
unprocessed results. Called by all execute methods.
throws: SQLException - if an error occurs |
notImplemented | static void notImplemented(String method) throws SQLException(Code) | | Report that user tried to call a method which has not been implemented.
Parameters: method - The method name to report in the error message. throws: SQLException - |
setEscapeProcessing | public void setEscapeProcessing(boolean enable) throws SQLException(Code) | | |
useCursor | protected boolean useCursor(boolean returnKeys, String sqlWord)(Code) | | Determines whether a cursor should be used based on the requested result
set type and concurrency, whether a cursor name has been set, the
useCursors connection property has been set, the first
word in the SQL query is either SELECT or EXEC/EXECUTE and no generated
keys are returned.
Parameters: returnKeys - indicates whether keys will be returned by the query Parameters: sqlWord - the first word in the SQL query; can benull if the caller isJtdsStatement.executeQuery true if a cursor should be used, false if not |
|
|