|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sourceforge.jtds.jdbc.JtdsStatement
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:
Statement
,
Connection.createStatement()
,
ResultSet
Field Summary | |
protected java.util.ArrayList |
batchValues
Batched SQL Statement array. |
(package private) static int |
BOOLEAN
|
(package private) static int |
CLOSE_ALL_RESULTS
|
(package private) static int |
CLOSE_CURRENT_RESULT
|
protected boolean |
closed
True if this statement is closed. |
protected ConnectionJDBC2 |
connection
The connection owning this statement object. |
protected JtdsResultSet |
currentResult
The current ResultSet . |
protected java.lang.String |
cursorName
The cursor name to be used for positioned updates. |
(package private) static int |
DATALINK
|
protected boolean |
escapeProcessing
True if SQL statements should be preprocessed. |
(package private) static java.lang.Integer |
EXECUTE_FAILED
|
protected int |
fetchDirection
The fetch direction for result sets. |
protected int |
fetchSize
The fetch size (default 100, only used by cursor ResultSet s). |
protected JtdsResultSet |
genKeyResultSet
Dummy result set for getGeneratedKeys. |
(package private) static int |
KEEP_CURRENT_RESULT
|
protected int |
maxFieldSize
The maximum field size (not used at present). |
protected int |
maxRows
The maximum number of rows to return (not used at present). |
protected SQLDiagnostic |
messages
SQL Diagnostic exceptions and warnings. |
(package private) static int |
NO_GENERATED_KEYS
|
protected java.util.ArrayList |
openResultSets
List of open result sets. |
protected int |
queryTimeout
The read query timeout in seconds |
protected java.util.LinkedList |
resultQueue
List of queued results (update counts, possibly followed by a ResultSet ). |
protected int |
resultSetConcurrency
The concurrency of result sets created by this statement. |
protected int |
resultSetType
The type of result sets created by this statement. |
(package private) static int |
RETURN_GENERATED_KEYS
|
(package private) static java.lang.Integer |
SUCCESS_NO_INFO
|
protected TdsCore |
tds
The TDS object used for server access. |
private int |
updateCount
The current update count. |
Constructor Summary | |
(package private) |
JtdsStatement(ConnectionJDBC2 connection,
int resultSetType,
int resultSetConcurrency)
Construct a new Statement object. |
Method Summary | |
void |
addBatch(java.lang.String sql)
|
(package private) void |
addWarning(java.sql.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 ). |
void |
cancel()
|
protected void |
checkOpen()
Check that this statement is still open. |
void |
clearBatch()
|
void |
clearWarnings()
|
void |
close()
|
(package private) void |
closeAllResultSets()
Close all result sets. |
(package private) void |
closeCurrentResultSet()
Close current result set (if any). |
boolean |
execute(java.lang.String sql)
|
boolean |
execute(java.lang.String sql,
int autoGeneratedKeys)
|
boolean |
execute(java.lang.String sql,
int[] columnIndexes)
|
boolean |
execute(java.lang.String sql,
java.lang.String[] columnNames)
|
int[] |
executeBatch()
Execute batch of SQL Statements. |
protected void |
executeBatchOther(java.lang.Object value,
boolean last)
This method should be over-ridden by any sub-classes that place values other than String s into the batchValues list
to handle execution properly. |
java.sql.ResultSet |
executeQuery(java.lang.String sql)
|
protected boolean |
executeSQL(java.lang.String sql,
java.lang.String spName,
java.lang.String sqlWord,
ParamInfo[] params,
boolean returnKeys,
boolean update)
Execute any type of SQL. |
protected java.sql.ResultSet |
executeSQLQuery(java.lang.String sql,
java.lang.String spName,
ParamInfo[] params)
Execute SQL to obtain a result set. |
int |
executeUpdate(java.lang.String sql)
|
int |
executeUpdate(java.lang.String sql,
int autoGeneratedKeys)
|
int |
executeUpdate(java.lang.String sql,
int[] columnIndexes)
|
int |
executeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
|
protected void |
finalize()
Called when this object goes out of scope to close any resultSet object and this statement. |
java.sql.Connection |
getConnection()
|
int |
getFetchDirection()
|
int |
getFetchSize()
|
java.sql.ResultSet |
getGeneratedKeys()
|
int |
getMaxFieldSize()
|
int |
getMaxRows()
|
(package private) SQLDiagnostic |
getMessages()
Get the statement's warnings list. |
boolean |
getMoreResults()
|
boolean |
getMoreResults(int current)
|
int |
getQueryTimeout()
|
java.sql.ResultSet |
getResultSet()
|
int |
getResultSetConcurrency()
|
int |
getResultSetHoldability()
|
int |
getResultSetType()
|
(package private) TdsCore |
getTds()
Get the Statement's TDS object. |
int |
getUpdateCount()
|
protected int |
getUpdateCount(int defaultValue)
Returns the first update count in resultQueue or the specified
default value if the queue is empty. |
java.sql.SQLWarning |
getWarnings()
|
protected void |
initialize()
Initialize the Statement , by cleaning up all queued and
unprocessed results. |
(package private) void |
notImplemented(java.lang.String method)
Report that user tried to call a method which has not been implemented. |
private boolean |
processResults(boolean returnKeys,
boolean update)
Queue up update counts into resultQueue until the end of the
response is reached or a ResultSet is encountered. |
void |
setCursorName(java.lang.String name)
|
void |
setEscapeProcessing(boolean enable)
|
void |
setFetchDirection(int direction)
|
void |
setFetchSize(int rows)
|
void |
setMaxFieldSize(int max)
|
void |
setMaxRows(int max)
|
void |
setQueryTimeout(int seconds)
|
Methods inherited from class java.lang.Object |
|
Field Detail |
static final int RETURN_GENERATED_KEYS
static final int NO_GENERATED_KEYS
static final int CLOSE_CURRENT_RESULT
static final int KEEP_CURRENT_RESULT
static final int CLOSE_ALL_RESULTS
static final int BOOLEAN
static final int DATALINK
static final java.lang.Integer SUCCESS_NO_INFO
static final java.lang.Integer EXECUTE_FAILED
protected ConnectionJDBC2 connection
protected TdsCore tds
protected int queryTimeout
protected JtdsResultSet currentResult
ResultSet
.private int updateCount
protected int fetchDirection
protected int resultSetType
protected int resultSetConcurrency
protected int fetchSize
ResultSet
s).protected java.lang.String cursorName
protected boolean closed
protected int maxFieldSize
protected int maxRows
protected boolean escapeProcessing
protected SQLDiagnostic messages
protected java.util.ArrayList batchValues
protected JtdsResultSet genKeyResultSet
protected java.util.LinkedList resultQueue
ResultSet
).protected java.util.ArrayList openResultSets
Constructor Detail |
JtdsStatement(ConnectionJDBC2 connection, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
connection
- The parent connection.resultSetType
- The result set type for example TYPE_FORWARD_ONLY.resultSetConcurrency
- The concurrency for example CONCUR_READ_ONLY.Method Detail |
protected void finalize()
finalize
in class java.lang.Object
TdsCore getTds()
TdsCore Object.
SQLDiagnostic getMessages()
SQLDiagnostic
.protected void checkOpen() throws java.sql.SQLException
java.sql.SQLException
- if statement closed.void notImplemented(java.lang.String method) throws java.sql.SQLException
method
- The method name to report in the error message.java.sql.SQLException
- void closeCurrentResultSet() throws java.sql.SQLException
void closeAllResultSets() throws java.sql.SQLException
void addWarning(java.sql.SQLWarning w)
w
- The SQLWarning to add.protected void executeBatchOther(java.lang.Object value, boolean last) throws java.sql.SQLException
String
s into the batchValues
list
to handle execution properly.value
- SQL String
or list of parameters to executelast
- true
if this is the last query/parameter list
in the batchprotected java.sql.ResultSet executeSQLQuery(java.lang.String sql, java.lang.String spName, ParamInfo[] params) throws java.sql.SQLException
sql
- The SQL statement to execute.spName
- Optional stored procedure name.params
- Optional parameters.ResultSet
.java.sql.SQLException
- protected boolean executeSQL(java.lang.String sql, java.lang.String spName, java.lang.String sqlWord, ParamInfo[] params, boolean returnKeys, boolean update) throws java.sql.SQLException
sql
- The SQL statement to execute.spName
- Optional stored procedure name.params
- Optional parameters.boolean
true if a result set is returned by the statement.java.sql.SQLException
- if an error condition occursprivate boolean processResults(boolean returnKeys, boolean update) throws java.sql.SQLException
resultQueue
until the end of the
response is reached or a ResultSet
is encountered. Calling
processResults
while a ResultSet
is open will
not close it, but will consume all remaining rows.returnKeys
- true
if a generated keys
ResultSet
is expectedupdate
- true
if the method is called from within
executeUpdate
true
if there are any results,
false
otherwisejava.sql.SQLException
- if an error condition occursprotected void cacheResults() throws java.sql.SQLException
ResultSet
). Called by ResultSet
s when the
end is reached.protected void initialize() throws java.sql.SQLException
Statement
, by cleaning up all queued and
unprocessed results. Called by all execute methods.java.sql.SQLException
- if an error occursprotected int getUpdateCount(int defaultValue)
resultQueue
or the specified
default value if the queue is empty.defaultValue
- the value to return if there are no queued update
counts (0 if called from executeUpdate
,
-1 if called from getMoreResults
)public int getFetchDirection() throws java.sql.SQLException
getFetchDirection
in interface java.sql.Statement
public int getFetchSize() throws java.sql.SQLException
getFetchSize
in interface java.sql.Statement
public int getMaxFieldSize() throws java.sql.SQLException
getMaxFieldSize
in interface java.sql.Statement
public int getMaxRows() throws java.sql.SQLException
getMaxRows
in interface java.sql.Statement
public int getQueryTimeout() throws java.sql.SQLException
getQueryTimeout
in interface java.sql.Statement
public int getResultSetConcurrency() throws java.sql.SQLException
getResultSetConcurrency
in interface java.sql.Statement
public int getResultSetHoldability() throws java.sql.SQLException
public int getResultSetType() throws java.sql.SQLException
getResultSetType
in interface java.sql.Statement
public int getUpdateCount() throws java.sql.SQLException
getUpdateCount
in interface java.sql.Statement
public void cancel() throws java.sql.SQLException
cancel
in interface java.sql.Statement
public void clearBatch() throws java.sql.SQLException
clearBatch
in interface java.sql.Statement
public void clearWarnings() throws java.sql.SQLException
clearWarnings
in interface java.sql.Statement
public void close() throws java.sql.SQLException
close
in interface java.sql.Statement
public boolean getMoreResults() throws java.sql.SQLException
getMoreResults
in interface java.sql.Statement
public int[] executeBatch() throws java.sql.SQLException, java.sql.BatchUpdateException
EXECUTE_FAILED
in any
of the elements. If a failure has occurred the array length will be less
than the count of statements in the batch. For those servers that do
continue to execute a batch containing an error (e.g. Sybase), elements
may contain EXECUTE_FAILED
. Note: even here the array
length may also be shorter than the statement count if a serious error
has prevented the rest of the batch from being executed. In addition,
when executing batched stored procedures, Sybase will also stop after
the first error.executeBatch
in interface java.sql.Statement
int[]
public void setFetchDirection(int direction) throws java.sql.SQLException
setFetchDirection
in interface java.sql.Statement
public void setFetchSize(int rows) throws java.sql.SQLException
setFetchSize
in interface java.sql.Statement
public void setMaxFieldSize(int max) throws java.sql.SQLException
setMaxFieldSize
in interface java.sql.Statement
public void setMaxRows(int max) throws java.sql.SQLException
setMaxRows
in interface java.sql.Statement
public void setQueryTimeout(int seconds) throws java.sql.SQLException
setQueryTimeout
in interface java.sql.Statement
public boolean getMoreResults(int current) throws java.sql.SQLException
public void setEscapeProcessing(boolean enable) throws java.sql.SQLException
setEscapeProcessing
in interface java.sql.Statement
public int executeUpdate(java.lang.String sql) throws java.sql.SQLException
executeUpdate
in interface java.sql.Statement
public void addBatch(java.lang.String sql) throws java.sql.SQLException
addBatch
in interface java.sql.Statement
public void setCursorName(java.lang.String name) throws java.sql.SQLException
setCursorName
in interface java.sql.Statement
public boolean execute(java.lang.String sql) throws java.sql.SQLException
execute
in interface java.sql.Statement
public int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
public boolean execute(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
public int executeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
public boolean execute(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface java.sql.Statement
public java.sql.ResultSet getGeneratedKeys() throws java.sql.SQLException
public java.sql.ResultSet getResultSet() throws java.sql.SQLException
getResultSet
in interface java.sql.Statement
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException
getWarnings
in interface java.sql.Statement
public int executeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
public boolean execute(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
public java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLException
executeQuery
in interface java.sql.Statement
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |