Package com.microsoft.sqlserver.jdbc
Class SQLServerStatement
- java.lang.Object
-
- com.microsoft.sqlserver.jdbc.SQLServerStatement
-
- All Implemented Interfaces:
ISQLServerStatement
,java.io.Serializable
,java.lang.AutoCloseable
,java.sql.Statement
,java.sql.Wrapper
- Direct Known Subclasses:
SQLServerPreparedStatement
public class SQLServerStatement extends java.lang.Object implements ISQLServerStatement
Provides an implementation of java.sql.Statement JDBC Interface to assist in creating Statements against SQL Server. It also provides a number of base class implementation methods for the JDBC prepared statement and callable Statements. SQLServerStatement's basic role is to execute SQL statements and return update counts and resultset rows to the user application. Documentation for specific public methods that are undocumented can be found under Sun's standard JDBC documentation for class java.sql.Statement. Those methods are part of Sun's standard JDBC documentation and therefore their documentation is not duplicated here.Implementation Notes
Fetching Result sets
The queries first rowset is available immediately after the executeQuery. The first rs.next() does not make a server round trip. For non server side resultsets the entire result set is in the rowset. For server side result sets the number of rows in the rowset is set with nFetchSize
The API javadoc for JDBC API methods that this class implements are not repeated here. Please see Sun's JDBC API interfaces javadoc for those details.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected SQLServerStatementColumnEncryptionSetting
stmtColumnEncriptionSetting
-
Method Summary
Modifier and Type Method Description void
addBatch(java.lang.String sql)
void
cancel()
void
clearBatch()
void
clearWarnings()
void
close()
void
closeOnCompletion()
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()
Sends a batch of statements to the database.long[]
executeLargeBatch()
long
executeLargeUpdate(java.lang.String sql)
long
executeLargeUpdate(java.lang.String sql, int autoGeneratedKeys)
long
executeLargeUpdate(java.lang.String sql, int[] columnIndexes)
long
executeLargeUpdate(java.lang.String sql, java.lang.String[] columnNames)
java.sql.ResultSet
executeQuery(java.lang.String sql)
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)
int
getCancelQueryTimeout()
Returns thecancelQueryTimeout
property set on this SQLServerStatement object.java.sql.Connection
getConnection()
Returns the statement's connection.int
getFetchDirection()
int
getFetchSize()
java.sql.ResultSet
getGeneratedKeys()
long
getLargeMaxRows()
long
getLargeUpdateCount()
int
getMaxFieldSize()
int
getMaxRows()
boolean
getMoreResults()
Returns more results in the TDS stream.boolean
getMoreResults(int mode)
int
getQueryTimeout()
java.lang.String
getResponseBuffering()
Returns the response buffering mode for this SQLServerStatement object.java.sql.ResultSet
getResultSet()
int
getResultSetConcurrency()
int
getResultSetHoldability()
int
getResultSetType()
protected SQLServerStatementColumnEncryptionSetting
getStmtColumnEncriptionSetting()
int
getUpdateCount()
java.sql.SQLWarning
getWarnings()
boolean
isClosed()
boolean
isCloseOnCompletion()
boolean
isPoolable()
boolean
isWrapperFor(java.lang.Class<?> iface)
void
setCancelQueryTimeout(int seconds)
Sets thecancelQueryTimeout
property on this SQLServerStatement object to cancelqueryTimeout
set onConnection
orStatement
level.void
setCursorName(java.lang.String name)
void
setEscapeProcessing(boolean enable)
void
setFetchDirection(int nDir)
void
setFetchSize(int rows)
void
setLargeMaxRows(long max)
void
setMaxFieldSize(int max)
void
setMaxRows(int max)
void
setPoolable(boolean poolable)
void
setQueryTimeout(int seconds)
void
setResponseBuffering(java.lang.String value)
Sets the response buffering mode for this SQLServerStatement object to case-insensitive String full or adaptive.java.lang.String
toString()
Returns the statement's id for logging info<T> T
unwrap(java.lang.Class<T> iface)
-
-
-
Field Detail
-
stmtColumnEncriptionSetting
protected SQLServerStatementColumnEncryptionSetting stmtColumnEncriptionSetting
-
-
Method Detail
-
getStmtColumnEncriptionSetting
protected SQLServerStatementColumnEncryptionSetting getStmtColumnEncriptionSetting()
-
toString
public java.lang.String toString()
Returns the statement's id for logging info- Overrides:
toString
in classjava.lang.Object
-
close
public void close() throws SQLServerException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
closeOnCompletion
public void closeOnCompletion() throws java.sql.SQLException
- Specified by:
closeOnCompletion
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeQuery
public java.sql.ResultSet executeQuery(java.lang.String sql) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
executeQuery
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
executeUpdate
public int executeUpdate(java.lang.String sql) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
executeUpdate
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
executeLargeUpdate
public long executeLargeUpdate(java.lang.String sql) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
executeLargeUpdate
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
execute
public boolean execute(java.lang.String sql) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
execute
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
getMaxFieldSize
public final int getMaxFieldSize() throws SQLServerException
- Specified by:
getMaxFieldSize
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
setMaxFieldSize
public final void setMaxFieldSize(int max) throws SQLServerException
- Specified by:
setMaxFieldSize
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getMaxRows
public final int getMaxRows() throws SQLServerException
- Specified by:
getMaxRows
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getLargeMaxRows
public final long getLargeMaxRows() throws SQLServerException
- Specified by:
getLargeMaxRows
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
setMaxRows
public final void setMaxRows(int max) throws SQLServerException
- Specified by:
setMaxRows
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
setLargeMaxRows
public final void setLargeMaxRows(long max) throws SQLServerException
- Specified by:
setLargeMaxRows
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
setEscapeProcessing
public final void setEscapeProcessing(boolean enable) throws SQLServerException
- Specified by:
setEscapeProcessing
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getQueryTimeout
public final int getQueryTimeout() throws SQLServerException
- Specified by:
getQueryTimeout
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
setQueryTimeout
public final void setQueryTimeout(int seconds) throws SQLServerException
- Specified by:
setQueryTimeout
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getCancelQueryTimeout
public final int getCancelQueryTimeout() throws SQLServerException
Description copied from interface:ISQLServerStatement
Returns thecancelQueryTimeout
property set on this SQLServerStatement object.- Specified by:
getCancelQueryTimeout
in interfaceISQLServerStatement
- Returns:
- cancelQueryTimeout Time duration in seconds.
- Throws:
SQLServerException
- if any error occurs
-
setCancelQueryTimeout
public final void setCancelQueryTimeout(int seconds) throws SQLServerException
Description copied from interface:ISQLServerStatement
Sets thecancelQueryTimeout
property on this SQLServerStatement object to cancelqueryTimeout
set onConnection
orStatement
level.- Specified by:
setCancelQueryTimeout
in interfaceISQLServerStatement
- Parameters:
seconds
- Time duration in seconds.- Throws:
SQLServerException
- if any error occurs
-
cancel
public final void cancel() throws SQLServerException
- Specified by:
cancel
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getWarnings
public final java.sql.SQLWarning getWarnings() throws SQLServerException
- Specified by:
getWarnings
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
clearWarnings
public final void clearWarnings() throws SQLServerException
- Specified by:
clearWarnings
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
setCursorName
public final void setCursorName(java.lang.String name) throws SQLServerException
- Specified by:
setCursorName
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getResultSet
public final java.sql.ResultSet getResultSet() throws SQLServerException
- Specified by:
getResultSet
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getUpdateCount
public final int getUpdateCount() throws SQLServerException
- Specified by:
getUpdateCount
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getLargeUpdateCount
public final long getLargeUpdateCount() throws SQLServerException
- Specified by:
getLargeUpdateCount
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getMoreResults
public final boolean getMoreResults() throws SQLServerException
Returns more results in the TDS stream.- Specified by:
getMoreResults
in interfacejava.sql.Statement
- Returns:
- true if the next result is a ResultSet object; false if it is an integer (indicating that it is an update count or there are no more results).
- Throws:
SQLServerException
-
setFetchDirection
public final void setFetchDirection(int nDir) throws SQLServerException
- Specified by:
setFetchDirection
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getFetchDirection
public final int getFetchDirection() throws SQLServerException
- Specified by:
getFetchDirection
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
setFetchSize
public final void setFetchSize(int rows) throws SQLServerException
- Specified by:
setFetchSize
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getFetchSize
public final int getFetchSize() throws SQLServerException
- Specified by:
getFetchSize
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getResultSetConcurrency
public final int getResultSetConcurrency() throws SQLServerException
- Specified by:
getResultSetConcurrency
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getResultSetType
public final int getResultSetType() throws SQLServerException
- Specified by:
getResultSetType
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
addBatch
public void addBatch(java.lang.String sql) throws SQLServerException
- Specified by:
addBatch
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
clearBatch
public void clearBatch() throws SQLServerException
- Specified by:
clearBatch
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
executeBatch
public int[] executeBatch() throws SQLServerException, java.sql.BatchUpdateException, java.sql.SQLTimeoutException
Sends a batch of statements to the database.- Specified by:
executeBatch
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.BatchUpdateException
java.sql.SQLTimeoutException
-
executeLargeBatch
public long[] executeLargeBatch() throws SQLServerException, java.sql.BatchUpdateException, java.sql.SQLTimeoutException
- Specified by:
executeLargeBatch
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.BatchUpdateException
java.sql.SQLTimeoutException
-
getConnection
public final java.sql.Connection getConnection() throws SQLServerException
Returns the statement's connection.- Specified by:
getConnection
in interfacejava.sql.Statement
- Returns:
- the connection
- Throws:
SQLServerException
- when an error occurs
-
getResultSetHoldability
public final int getResultSetHoldability() throws java.sql.SQLException
- Specified by:
getResultSetHoldability
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
execute
public final boolean execute(java.lang.String sql, int autoGeneratedKeys) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
execute
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
execute
public final boolean execute(java.lang.String sql, int[] columnIndexes) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
execute
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
execute
public final boolean execute(java.lang.String sql, java.lang.String[] columnNames) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
execute
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
executeUpdate
public final int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
executeUpdate
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
executeLargeUpdate
public final long executeLargeUpdate(java.lang.String sql, int autoGeneratedKeys) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
executeLargeUpdate
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
executeUpdate
public final int executeUpdate(java.lang.String sql, int[] columnIndexes) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
executeUpdate
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
executeLargeUpdate
public final long executeLargeUpdate(java.lang.String sql, int[] columnIndexes) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
executeLargeUpdate
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
executeUpdate
public final int executeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
executeUpdate
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
executeLargeUpdate
public final long executeLargeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws SQLServerException, java.sql.SQLTimeoutException
- Specified by:
executeLargeUpdate
in interfacejava.sql.Statement
- Throws:
SQLServerException
java.sql.SQLTimeoutException
-
getGeneratedKeys
public final java.sql.ResultSet getGeneratedKeys() throws SQLServerException
- Specified by:
getGeneratedKeys
in interfacejava.sql.Statement
- Throws:
SQLServerException
-
getMoreResults
public final boolean getMoreResults(int mode) throws java.sql.SQLException
- Specified by:
getMoreResults
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
isClosed
public boolean isClosed() throws java.sql.SQLException
- Specified by:
isClosed
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
isCloseOnCompletion
public boolean isCloseOnCompletion() throws java.sql.SQLException
- Specified by:
isCloseOnCompletion
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
isPoolable
public boolean isPoolable() throws java.sql.SQLException
- Specified by:
isPoolable
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setPoolable
public void setPoolable(boolean poolable) throws java.sql.SQLException
- Specified by:
setPoolable
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
- Specified by:
isWrapperFor
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
setResponseBuffering
public final void setResponseBuffering(java.lang.String value) throws SQLServerException
Description copied from interface:ISQLServerStatement
Sets the response buffering mode for this SQLServerStatement object to case-insensitive String full or adaptive.Response buffering controls the driver's buffering of responses from SQL Server.
Possible values are:
"full" - Fully buffer the response at execution time.
"adaptive" - Data Pipe adaptive buffering
- Specified by:
setResponseBuffering
in interfaceISQLServerStatement
- Parameters:
value
- A String that contains the response buffering mode. The valid mode can be one of the following case-insensitive Strings: full or adaptive.- Throws:
SQLServerException
- If there are any errors in setting the response buffering mode.
-
getResponseBuffering
public final java.lang.String getResponseBuffering() throws SQLServerException
Description copied from interface:ISQLServerStatement
Returns the response buffering mode for this SQLServerStatement object.- Specified by:
getResponseBuffering
in interfaceISQLServerStatement
- Returns:
- A String that contains a lower-case full or adaptive.
- Throws:
SQLServerException
- If there are any errors in retrieving the response buffering mode.
-
-