Class JtdsPreparedStatement
- All Implemented Interfaces:
AutoCloseable
,PreparedStatement
,Statement
,Wrapper
- Direct Known Subclasses:
JtdsCallableStatement
Implementation notes:
- Generally a simple subclass of Statement mainly adding support for the setting of parameters.
- The stream logic is taken over from the work Brian did to add Blob support to the original jTDS.
- Use of Statement specific method calls eg executeQuery(sql) is blocked by this version of the driver. This is unlike the original jTDS but inline with all the other JDBC drivers that I have been able to test.
- Author:
- Brian Heineman, Mike Hutchinson, Holger Rehn
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final NumberFormat
Used to format numeric values when scale is specified.(package private) Collection
Collection of handles used by this statementprivate final String
The original SQL statement provided at construction time.protected ParamInfo[]
The parameter list for the call.protected ParamInfo[]
The cached parameter meta data.protected String
The procedure name for CallableStatements.private boolean
True to return generated keys.protected final String
The SQL statement being prepared.protected String
The first SQL keyword in the SQL string.Fields inherited from class net.sourceforge.jtds.jdbc.JtdsStatement
batchValues, BOOLEAN, CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, colMetaData, connection, currentResult, cursorName, DATALINK, DEFAULT_FETCH_SIZE, escapeProcessing, EXECUTE_FAILED, fetchDirection, fetchSize, GENKEYCOL, genKeyResultSet, KEEP_CURRENT_RESULT, maxFieldSize, maxRows, messages, NO_GENERATED_KEYS, openResultSets, queryTimeout, resultQueue, resultSetConcurrency, resultSetType, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO, tds
Fields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO
-
Constructor Summary
ConstructorsConstructorDescriptionJtdsPreparedStatement
(JtdsConnection connection, String sql, int resultSetType, int concurrency, boolean returnKeys) Construct a new preparedStatement object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBatch()
void
protected void
Check that this statement is still open.void
void
close()
boolean
execute()
boolean
boolean
boolean
boolean
protected SQLException
executeMSBatch
(int size, int executeSize, ArrayList counts) Execute the SQL batch on a MS server.executeQuery
(String sql) protected SQLException
executeSybaseBatch
(int size, int executeSize, ArrayList counts) Execute the SQL batch on a Sybase server.int
int
executeUpdate
(String sql) int
executeUpdate
(String sql, int getKeys) int
executeUpdate
(String arg0, int[] arg1) int
executeUpdate
(String arg0, String[] arg1) protected ParamInfo
getParameter
(int parameterIndex) Check the supplied index and return the selected parameter.private static String
This method converts native call syntax into (hopefully) valid JDBC escape syntax.protected static String
normalizeCall
(String sql) This method converts native call syntax into (hopefully) valid JDBC escape syntax.protected void
notSupported
(String method) Report that user tried to call a method not supported on this type of statement.private static boolean
openComment
(String sql, int offset) void
void
setAsciiStream
(int parameterIndex, InputStream x) void
setAsciiStream
(int parameterIndex, InputStream inputStream, int length) void
setAsciiStream
(int parameterIndex, InputStream x, long length) void
setBigDecimal
(int parameterIndex, BigDecimal x) void
setBinaryStream
(int parameterIndex, InputStream x) void
setBinaryStream
(int parameterIndex, InputStream x, int length) void
setBinaryStream
(int parameterIndex, InputStream x, long length) void
setBlob
(int parameterIndex, InputStream inputStream) void
setBlob
(int parameterIndex, InputStream inputStream, long length) void
void
setBoolean
(int parameterIndex, boolean x) void
setByte
(int parameterIndex, byte x) void
setBytes
(int parameterIndex, byte[] x) void
setCharacterStream
(int parameterIndex, Reader reader) void
setCharacterStream
(int parameterIndex, Reader reader, int length) void
setCharacterStream
(int parameterIndex, Reader reader, long length) void
void
void
(package private) void
setColMetaData
(ColInfo[] value) Update the cached column meta data information.void
void
void
setDouble
(int parameterIndex, double x) void
setFloat
(int parameterIndex, float x) void
setInt
(int parameterIndex, int x) void
setLong
(int parameterIndex, long x) void
setNCharacterStream
(int parameterIndex, Reader value) void
setNCharacterStream
(int parameterIndex, Reader value, long length) void
void
void
void
setNString
(int parameterIndex, String value) void
setNull
(int parameterIndex, int sqlType) void
void
void
void
void
setObjectBase
(int parameterIndex, Object x, int targetSqlType, int scale) Generic setObject method.protected void
setParameter
(int parameterIndex, Object x, int targetSqlType, int scale, int length) Update the ParamInfo object for the specified parameter.(package private) void
setParamMetaData
(ParamInfo[] value) Update the cached parameter meta data information.void
void
void
setShort
(int parameterIndex, short x) void
void
void
void
void
setTimestamp
(int parameterIndex, Timestamp x) void
setTimestamp
(int parameterIndex, Timestamp x, Calendar cal) void
setUnicodeStream
(int parameterIndex, InputStream inputStream, int length) void
toString()
Returns the SQL command provided at construction time.Methods inherited from class net.sourceforge.jtds.jdbc.JtdsStatement
addWarning, cacheResults, cancel, checkCursorException, clearBatch, clearWarnings, closeAllResultSets, closeCurrentResultSet, closeOnCompletion, executeBatch, executeSQL, executeSQLQuery, finalize, getConnection, getDefaultFetchSize, getFetchDirection, getFetchSize, getGeneratedKeys, getMaxFieldSize, getMaxRows, getMessages, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getTds, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isWrapperFor, notImplemented, reset, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout, unwrap, useCursor
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.sql.PreparedStatement
executeLargeUpdate, setObject, setObject
Methods inherited from interface java.sql.Statement
cancel, clearBatch, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, executeBatch, executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isSimpleIdentifier, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
Field Details
-
sql
The SQL statement being prepared. -
originalSql
The original SQL statement provided at construction time. -
sqlWord
The first SQL keyword in the SQL string. -
procName
The procedure name for CallableStatements. -
parameters
The parameter list for the call. -
returnKeys
private boolean returnKeysTrue to return generated keys. -
paramMetaData
The cached parameter meta data. -
f
Used to format numeric values when scale is specified. -
handles
Collection handlesCollection of handles used by this statement
-
-
Constructor Details
-
JtdsPreparedStatement
JtdsPreparedStatement(JtdsConnection connection, String sql, int resultSetType, int concurrency, boolean returnKeys) throws SQLException Construct a new preparedStatement object.- Parameters:
connection
- The parent connection.sql
- The SQL statement to prepare.resultSetType
- The result set type eg SCROLLABLE etc.concurrency
- The result set concurrency eg READONLY.returnKeys
- True if generated keys should be returned.- Throws:
SQLException
-
-
Method Details
-
toString
Returns the SQL command provided at construction time. -
normalizeCall
This method converts native call syntax into (hopefully) valid JDBC escape syntax.
Note: This method is required for backwards compatibility with previous versions of jTDS. Strictly speaking only the JDBC syntax needs to be recognized, constructions such as "?=#testproc ?,?" are neither valid native syntax nor valid escapes. All the substrings and trims below are not as bad as they look. The objects created all refer back to the original SQL string it is just the start and length positions which change.
- Parameters:
sql
- the SQL statement to process- Returns:
- the SQL, possibly in original form
- Throws:
SQLException
- if the SQL statement is detected to be a normal SQL INSERT, UPDATE or DELETE statement instead of a procedure call
-
normalize
This method converts native call syntax into (hopefully) valid JDBC escape syntax.
Note: This method is required for backwards compatibility with previous versions of jTDS. Strictly speaking only the JDBC syntax needs to be recognized, constructions such as "?=#testproc ?,?" are neither valid native syntax nor valid escapes. All the substrings and trims below are not as bad as they look. The objects created all refer back to the original SQL string it is just the start and length positions which change.
- Parameters:
sql
- the SQL statement to process- Returns:
- the SQL, possibly in original form
- Throws:
SQLException
- if the SQL statement is detected to be a normal SQL INSERT, UPDATE or DELETE statement instead of a procedure call
-
openComment
- Throws:
SQLException
-
checkOpen
Check that this statement is still open.- Overrides:
checkOpen
in classJtdsStatement
- Throws:
SQLException
- if statement closed.
-
notSupported
Report that user tried to call a method not supported on this type of statement.- Parameters:
method
- The method name to report in the error message.- Throws:
SQLException
-
executeMSBatch
protected SQLException executeMSBatch(int size, int executeSize, ArrayList counts) throws SQLException Execute the SQL batch on a MS server. When running withprepareSQL=1
or3
, the driver will first prepare temporary stored procedures or statements for each parameter combination found in the batch. The handles to these pre-preared statements will then be used to execute the actual batch statements.- Overrides:
executeMSBatch
in classJtdsStatement
- Parameters:
size
- the total size of the batchexecuteSize
- the maximum number of statements to send in one requestcounts
- the returned update counts- Returns:
- chained exceptions linked to a
SQLException
- Throws:
SQLException
- if a serious error occurs during execution
-
executeSybaseBatch
protected SQLException executeSybaseBatch(int size, int executeSize, ArrayList counts) throws SQLException Execute the SQL batch on a Sybase server. Sybase needs to have the SQL concatenated into one TDS language packet followed by up to 1000 parameters. This method will be overridden forCallableStatements
.- Overrides:
executeSybaseBatch
in classJtdsStatement
- Parameters:
size
- the total size of the batchexecuteSize
- the maximum number of statements to send in one requestcounts
- the returned update counts- Returns:
- chained exceptions linked to a
SQLException
- Throws:
SQLException
- if a serious error occurs during execution
-
getParameter
Check the supplied index and return the selected parameter.- Parameters:
parameterIndex
- the parameter index 1 to n.- Returns:
- the parameter as a
ParamInfo
object. - Throws:
SQLException
- if the statement is closed; ifparameterIndex
is less than 0; ifparameterIndex
is greater than the number of parameters; ifcheckIfSet
wastrue
and the parameter was not set
-
setObjectBase
public void setObjectBase(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException Generic setObject method.- Parameters:
parameterIndex
- Parameter index 1 to n.x
- The value to set.targetSqlType
- The java.sql.Types constant describing the data.scale
- The decimal scale -1 if not set.- Throws:
SQLException
-
setParameter
protected void setParameter(int parameterIndex, Object x, int targetSqlType, int scale, int length) throws SQLException Update the ParamInfo object for the specified parameter.- Parameters:
parameterIndex
- Parameter index 1 to n.x
- The value to set.targetSqlType
- The java.sql.Types constant describing the data.scale
- The decimal scale -1 if not set.length
- The length of the data item.- Throws:
SQLException
-
setColMetaData
Update the cached column meta data information.- Parameters:
value
- The Column meta data array.
-
setParamMetaData
Update the cached parameter meta data information.- Parameters:
value
- The Column meta data array.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceStatement
- Overrides:
close
in classJtdsStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfacePreparedStatement
- Throws:
SQLException
-
addBatch
- Specified by:
addBatch
in interfacePreparedStatement
- Throws:
SQLException
-
clearParameters
- Specified by:
clearParameters
in interfacePreparedStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfacePreparedStatement
- Throws:
SQLException
-
setByte
- Specified by:
setByte
in interfacePreparedStatement
- Throws:
SQLException
-
setDouble
- Specified by:
setDouble
in interfacePreparedStatement
- Throws:
SQLException
-
setFloat
- Specified by:
setFloat
in interfacePreparedStatement
- Throws:
SQLException
-
setInt
- Specified by:
setInt
in interfacePreparedStatement
- Throws:
SQLException
-
setNull
- Specified by:
setNull
in interfacePreparedStatement
- Throws:
SQLException
-
setLong
- Specified by:
setLong
in interfacePreparedStatement
- Throws:
SQLException
-
setShort
- Specified by:
setShort
in interfacePreparedStatement
- Throws:
SQLException
-
setBoolean
- Specified by:
setBoolean
in interfacePreparedStatement
- Throws:
SQLException
-
setBytes
- Specified by:
setBytes
in interfacePreparedStatement
- Throws:
SQLException
-
setAsciiStream
public void setAsciiStream(int parameterIndex, InputStream inputStream, int length) throws SQLException - Specified by:
setAsciiStream
in interfacePreparedStatement
- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStream
in interfacePreparedStatement
- Throws:
SQLException
-
setUnicodeStream
public void setUnicodeStream(int parameterIndex, InputStream inputStream, int length) throws SQLException - Specified by:
setUnicodeStream
in interfacePreparedStatement
- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStream
in interfacePreparedStatement
- Throws:
SQLException
-
setObject
- Specified by:
setObject
in interfacePreparedStatement
- Throws:
SQLException
-
setObject
- Specified by:
setObject
in interfacePreparedStatement
- Throws:
SQLException
-
setObject
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException - Specified by:
setObject
in interfacePreparedStatement
- Throws:
SQLException
-
setNull
- Specified by:
setNull
in interfacePreparedStatement
- Throws:
SQLException
-
setString
- Specified by:
setString
in interfacePreparedStatement
- Throws:
SQLException
-
setBigDecimal
- Specified by:
setBigDecimal
in interfacePreparedStatement
- Throws:
SQLException
-
setURL
- Specified by:
setURL
in interfacePreparedStatement
- Throws:
SQLException
-
setArray
- Specified by:
setArray
in interfacePreparedStatement
- Throws:
SQLException
-
setBlob
- Specified by:
setBlob
in interfacePreparedStatement
- Throws:
SQLException
-
setClob
- Specified by:
setClob
in interfacePreparedStatement
- Throws:
SQLException
-
setDate
- Specified by:
setDate
in interfacePreparedStatement
- Throws:
SQLException
-
getParameterMetaData
- Specified by:
getParameterMetaData
in interfacePreparedStatement
- Throws:
SQLException
-
setRef
- Specified by:
setRef
in interfacePreparedStatement
- Throws:
SQLException
-
executeQuery
- Specified by:
executeQuery
in interfacePreparedStatement
- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaData
in interfacePreparedStatement
- Throws:
SQLException
-
setTime
- Specified by:
setTime
in interfacePreparedStatement
- Throws:
SQLException
-
setTimestamp
- Specified by:
setTimestamp
in interfacePreparedStatement
- Throws:
SQLException
-
setDate
- Specified by:
setDate
in interfacePreparedStatement
- Throws:
SQLException
-
setTime
- Specified by:
setTime
in interfacePreparedStatement
- Throws:
SQLException
-
setTimestamp
- Specified by:
setTimestamp
in interfacePreparedStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Overrides:
executeUpdate
in classJtdsStatement
- Throws:
SQLException
-
addBatch
- Specified by:
addBatch
in interfaceStatement
- Overrides:
addBatch
in classJtdsStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Overrides:
execute
in classJtdsStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Overrides:
executeUpdate
in classJtdsStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Overrides:
execute
in classJtdsStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Overrides:
executeUpdate
in classJtdsStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Overrides:
execute
in classJtdsStatement
- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdate
in interfaceStatement
- Overrides:
executeUpdate
in classJtdsStatement
- Throws:
SQLException
-
execute
- Specified by:
execute
in interfaceStatement
- Overrides:
execute
in classJtdsStatement
- Throws:
SQLException
-
executeQuery
- Specified by:
executeQuery
in interfaceStatement
- Overrides:
executeQuery
in classJtdsStatement
- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStream
in interfacePreparedStatement
- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStream
in interfacePreparedStatement
- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStream
in interfacePreparedStatement
- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStream
in interfacePreparedStatement
- Throws:
SQLException
-
setBlob
- Specified by:
setBlob
in interfacePreparedStatement
- Throws:
SQLException
-
setBlob
- Specified by:
setBlob
in interfacePreparedStatement
- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStream
in interfacePreparedStatement
- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStream
in interfacePreparedStatement
- Throws:
SQLException
-
setClob
- Specified by:
setClob
in interfacePreparedStatement
- Throws:
SQLException
-
setClob
- Specified by:
setClob
in interfacePreparedStatement
- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStream
in interfacePreparedStatement
- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStream
in interfacePreparedStatement
- Throws:
SQLException
-
setNClob
- Specified by:
setNClob
in interfacePreparedStatement
- Throws:
SQLException
-
setNClob
- Specified by:
setNClob
in interfacePreparedStatement
- Throws:
SQLException
-
setNClob
- Specified by:
setNClob
in interfacePreparedStatement
- Throws:
SQLException
-
setNString
- Specified by:
setNString
in interfacePreparedStatement
- Throws:
SQLException
-
setRowId
- Specified by:
setRowId
in interfacePreparedStatement
- Throws:
SQLException
-
setSQLXML
- Specified by:
setSQLXML
in interfacePreparedStatement
- Throws:
SQLException
-