setObject(String parameterName, Object x, int targetSqlType, int scaleOrLength)

Syntax:

void setObject(String parameterName,
               Object x,
               int targetSqlType,
               int scaleOrLength)
               throws SQLException

Description:

Sets the value of the designated parameter with the given object. The second argument must be an object type; for integral values, the java.lang equivalent objects should be used. If the second argument is an InputStream then the stream must contain the number of bytes specified by scaleOrLength. If the second argument is a Reader then the reader must contain the number of characters specified by scaleOrLength. If these conditions are not true the driver will generate an SQLException when the prepared statement is executed.

The given Java object will be converted to the given targetSqlType before being sent to the database. If the object has a custom mapping (is of a class implementing the interface SQLData), the JDBC driver should call the method SQLData.writeSQL to write it to the SQL data stream. If, on the other hand, the object is of a class implementing Ref, Blob, Clob, NClob, Struct, java.net.URL, or Array, the driver should pass it to the database as a value of the corresponding SQL type.

Note that this method may be used to pass database-specific abstract data types.

Parameters:

parameterName

the name of the parameter

x

the parameter value

targetSqlType

the SQL type (as defined in java.sql.Types) to be sent to the database

scaleOrLength

for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types, this is the number of digits after the decimal point. For Java Object types InputStream and Reader, this is the length of the data in the stream or reader. For all other types, this value will be ignored.

Throws:

SQLException - if a database access error occurs, parameterName is not a valid parameter name, x is ambiguous or not a valid database type, or the prepared statement has been closed

SQLFeatureNotSupportedException - if targetSqlType is a ARRAY, DATALINK, JAVA_OBJECT, REF, ROWID, SQLXML, or STRUCT.

Reference:

For more information, reference JDBC documentation for: CallableStatement.setObject(String, Object, int, int)