I am setting an SQL prepared statement like this:
prd.setBytes(i+1, temp_value);
Where temp_value is of type byte[].
At the end i am adding the prd statement to a batch like this:
prd.addBatch();
prd.executeBatch();
The executeBatch gives me the exception:
java.sql.BatchUpdateException: Error converting data type varbinary to numeric.
Is it possible to simply add Bytes to a prepared statement no matter if the field in the DataBase table is of type Numeric or any other type?
Do i have to be speccific about the type i am inserting?
The
setBytesmethod is intended for use with SQL BLOB types, such asvarbinary,longvarbinary, and so on. For the numeric types you need to useBigDecimal,BigInteger, or a numeric primitive.The issue with allowing
setBytesto be used with non-binary types is system independence: you would need to match the driver’s expected layout for a multi-byte number with potentially vey complex structure that JDBC driver writers would need to publish. Once this layout is published, their driver would have to remain compatible with it for life. Most driver writers, however, would prefer to avoid such tight coupling with the client code.