setObject(int parameterIndex, Object x)
Syntax:
void setObject(int parameterIndex, Object x) throws SQLException
Description:
Sets the value of the designated parameter using the given object. The second parameter must be of type Object
; therefore, the java.lang
equivalent objects should be used for built-in types.
The JDBC specification specifies a standard mapping from Java Object
types to SQL types. The given argument will be converted to the corresponding SQL type before being sent to the database.
Note that this method may be used to pass database- specific abstract data types, by using a driver-specific Java type. If the object 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
, RowId
, SQLXML
or Array
, the driver should pass it to the database as a value of the corresponding SQL type.
Note: Not all databases allow for a non-typed Null to be sent to the backend. For maximum portability, the setNull
or the setObject(int parameterIndex, Object x, int sqlType)
method should be used instead of setObject(int parameterIndex, Object x)
.
Note: This method throws an exception if there is an ambiguity, for example, if the object is of a class implementing more than one of the interfaces named above.
Parameters:
parameterIndex
the first parameter is 1, the second is 2, ...
x
the parameter value
Throws:
SQLException - if a database access error occurs, parameterIndex is less than 1 or greater than the number of parameters, x is ambiguous or not a valid database type, or the prepared statement has been closed
Reference:
For more information, reference JDBC documentation for: PreparedStatement.setObject(int, Object)