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 NumberFormatUsed to format numeric values when scale is specified.(package private) CollectionCollection of handles used by this statementprivate final StringThe original SQL statement provided at construction time.protected ParamInfo[]The parameter list for the call.protected ParamInfo[]The cached parameter meta data.protected StringThe procedure name for CallableStatements.private booleanTrue to return generated keys.protected final StringThe SQL statement being prepared.protected StringThe 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, tdsFields 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 TypeMethodDescriptionvoidaddBatch()voidprotected voidCheck that this statement is still open.voidvoidclose()booleanexecute()booleanbooleanbooleanbooleanprotected SQLExceptionexecuteMSBatch(int size, int executeSize, ArrayList counts) Execute the SQL batch on a MS server.executeQuery(String sql) protected SQLExceptionexecuteSybaseBatch(int size, int executeSize, ArrayList counts) Execute the SQL batch on a Sybase server.intintexecuteUpdate(String sql) intexecuteUpdate(String sql, int getKeys) intexecuteUpdate(String arg0, int[] arg1) intexecuteUpdate(String arg0, String[] arg1) protected ParamInfogetParameter(int parameterIndex) Check the supplied index and return the selected parameter.private static StringThis method converts native call syntax into (hopefully) valid JDBC escape syntax.protected static StringnormalizeCall(String sql) This method converts native call syntax into (hopefully) valid JDBC escape syntax.protected voidnotSupported(String method) Report that user tried to call a method not supported on this type of statement.private static booleanopenComment(String sql, int offset) voidvoidsetAsciiStream(int parameterIndex, InputStream x) voidsetAsciiStream(int parameterIndex, InputStream inputStream, int length) voidsetAsciiStream(int parameterIndex, InputStream x, long length) voidsetBigDecimal(int parameterIndex, BigDecimal x) voidsetBinaryStream(int parameterIndex, InputStream x) voidsetBinaryStream(int parameterIndex, InputStream x, int length) voidsetBinaryStream(int parameterIndex, InputStream x, long length) voidsetBlob(int parameterIndex, InputStream inputStream) voidsetBlob(int parameterIndex, InputStream inputStream, long length) voidvoidsetBoolean(int parameterIndex, boolean x) voidsetByte(int parameterIndex, byte x) voidsetBytes(int parameterIndex, byte[] x) voidsetCharacterStream(int parameterIndex, Reader reader) voidsetCharacterStream(int parameterIndex, Reader reader, int length) voidsetCharacterStream(int parameterIndex, Reader reader, long length) voidvoidvoid(package private) voidsetColMetaData(ColInfo[] value) Update the cached column meta data information.voidvoidvoidsetDouble(int parameterIndex, double x) voidsetFloat(int parameterIndex, float x) voidsetInt(int parameterIndex, int x) voidsetLong(int parameterIndex, long x) voidsetNCharacterStream(int parameterIndex, Reader value) voidsetNCharacterStream(int parameterIndex, Reader value, long length) voidvoidvoidvoidsetNString(int parameterIndex, String value) voidsetNull(int parameterIndex, int sqlType) voidvoidvoidvoidvoidsetObjectBase(int parameterIndex, Object x, int targetSqlType, int scale) Generic setObject method.protected voidsetParameter(int parameterIndex, Object x, int targetSqlType, int scale, int length) Update the ParamInfo object for the specified parameter.(package private) voidsetParamMetaData(ParamInfo[] value) Update the cached parameter meta data information.voidvoidvoidsetShort(int parameterIndex, short x) voidvoidvoidvoidvoidsetTimestamp(int parameterIndex, Timestamp x) voidsetTimestamp(int parameterIndex, Timestamp x, Calendar cal) voidsetUnicodeStream(int parameterIndex, InputStream inputStream, int length) voidtoString()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, useCursorMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.sql.PreparedStatement
executeLargeUpdate, setObject, setObjectMethods 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, setQueryTimeoutMethods 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:
checkOpenin 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=1or3, 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:
executeMSBatchin 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:
executeSybaseBatchin 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
ParamInfoobject. - Throws:
SQLException- if the statement is closed; ifparameterIndexis less than 0; ifparameterIndexis greater than the number of parameters; ifcheckIfSetwastrueand 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceStatement- Overrides:
closein classJtdsStatement- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfacePreparedStatement- Throws:
SQLException
-
addBatch
- Specified by:
addBatchin interfacePreparedStatement- Throws:
SQLException
-
clearParameters
- Specified by:
clearParametersin interfacePreparedStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfacePreparedStatement- Throws:
SQLException
-
setByte
- Specified by:
setBytein interfacePreparedStatement- Throws:
SQLException
-
setDouble
- Specified by:
setDoublein interfacePreparedStatement- Throws:
SQLException
-
setFloat
- Specified by:
setFloatin interfacePreparedStatement- Throws:
SQLException
-
setInt
- Specified by:
setIntin interfacePreparedStatement- Throws:
SQLException
-
setNull
- Specified by:
setNullin interfacePreparedStatement- Throws:
SQLException
-
setLong
- Specified by:
setLongin interfacePreparedStatement- Throws:
SQLException
-
setShort
- Specified by:
setShortin interfacePreparedStatement- Throws:
SQLException
-
setBoolean
- Specified by:
setBooleanin interfacePreparedStatement- Throws:
SQLException
-
setBytes
- Specified by:
setBytesin interfacePreparedStatement- Throws:
SQLException
-
setAsciiStream
public void setAsciiStream(int parameterIndex, InputStream inputStream, int length) throws SQLException - Specified by:
setAsciiStreamin interfacePreparedStatement- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStreamin interfacePreparedStatement- Throws:
SQLException
-
setUnicodeStream
public void setUnicodeStream(int parameterIndex, InputStream inputStream, int length) throws SQLException - Specified by:
setUnicodeStreamin interfacePreparedStatement- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setObject
- Specified by:
setObjectin interfacePreparedStatement- Throws:
SQLException
-
setObject
- Specified by:
setObjectin interfacePreparedStatement- Throws:
SQLException
-
setObject
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException - Specified by:
setObjectin interfacePreparedStatement- Throws:
SQLException
-
setNull
- Specified by:
setNullin interfacePreparedStatement- Throws:
SQLException
-
setString
- Specified by:
setStringin interfacePreparedStatement- Throws:
SQLException
-
setBigDecimal
- Specified by:
setBigDecimalin interfacePreparedStatement- Throws:
SQLException
-
setURL
- Specified by:
setURLin interfacePreparedStatement- Throws:
SQLException
-
setArray
- Specified by:
setArrayin interfacePreparedStatement- Throws:
SQLException
-
setBlob
- Specified by:
setBlobin interfacePreparedStatement- Throws:
SQLException
-
setClob
- Specified by:
setClobin interfacePreparedStatement- Throws:
SQLException
-
setDate
- Specified by:
setDatein interfacePreparedStatement- Throws:
SQLException
-
getParameterMetaData
- Specified by:
getParameterMetaDatain interfacePreparedStatement- Throws:
SQLException
-
setRef
- Specified by:
setRefin interfacePreparedStatement- Throws:
SQLException
-
executeQuery
- Specified by:
executeQueryin interfacePreparedStatement- Throws:
SQLException
-
getMetaData
- Specified by:
getMetaDatain interfacePreparedStatement- Throws:
SQLException
-
setTime
- Specified by:
setTimein interfacePreparedStatement- Throws:
SQLException
-
setTimestamp
- Specified by:
setTimestampin interfacePreparedStatement- Throws:
SQLException
-
setDate
- Specified by:
setDatein interfacePreparedStatement- Throws:
SQLException
-
setTime
- Specified by:
setTimein interfacePreparedStatement- Throws:
SQLException
-
setTimestamp
- Specified by:
setTimestampin interfacePreparedStatement- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfaceStatement- Overrides:
executeUpdatein classJtdsStatement- Throws:
SQLException
-
addBatch
- Specified by:
addBatchin interfaceStatement- Overrides:
addBatchin classJtdsStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfaceStatement- Overrides:
executein classJtdsStatement- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfaceStatement- Overrides:
executeUpdatein classJtdsStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfaceStatement- Overrides:
executein classJtdsStatement- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfaceStatement- Overrides:
executeUpdatein classJtdsStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfaceStatement- Overrides:
executein classJtdsStatement- Throws:
SQLException
-
executeUpdate
- Specified by:
executeUpdatein interfaceStatement- Overrides:
executeUpdatein classJtdsStatement- Throws:
SQLException
-
execute
- Specified by:
executein interfaceStatement- Overrides:
executein classJtdsStatement- Throws:
SQLException
-
executeQuery
- Specified by:
executeQueryin interfaceStatement- Overrides:
executeQueryin classJtdsStatement- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStreamin interfacePreparedStatement- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStreamin interfacePreparedStatement- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStreamin interfacePreparedStatement- Throws:
SQLException
-
setBinaryStream
- Specified by:
setBinaryStreamin interfacePreparedStatement- Throws:
SQLException
-
setBlob
- Specified by:
setBlobin interfacePreparedStatement- Throws:
SQLException
-
setBlob
- Specified by:
setBlobin interfacePreparedStatement- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setClob
- Specified by:
setClobin interfacePreparedStatement- Throws:
SQLException
-
setClob
- Specified by:
setClobin interfacePreparedStatement- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setNCharacterStream
- Specified by:
setNCharacterStreamin interfacePreparedStatement- Throws:
SQLException
-
setNClob
- Specified by:
setNClobin interfacePreparedStatement- Throws:
SQLException
-
setNClob
- Specified by:
setNClobin interfacePreparedStatement- Throws:
SQLException
-
setNClob
- Specified by:
setNClobin interfacePreparedStatement- Throws:
SQLException
-
setNString
- Specified by:
setNStringin interfacePreparedStatement- Throws:
SQLException
-
setRowId
- Specified by:
setRowIdin interfacePreparedStatement- Throws:
SQLException
-
setSQLXML
- Specified by:
setSQLXMLin interfacePreparedStatement- Throws:
SQLException
-