I've been trying to persist a LocalDateTime into a TIMESTAMP column in DB2 10.5 but fails with the error:
[jcc][1091][10824][4.26.14] Invalid data conversion: Parameter instance 2020-01-02T12:34:56 is invalid for the requested conversion. ERRORCODE=-4461, SQLSTATE=42815
I'm using the IBM JDBC driver: "JDBC driver IBM Data Server Driver for JDBC and SQLJ 4.26.14" that implements JDBC spec 4.1.
The table definition is:
create table t1 (
id int,
a timestamp
);
And the Java code is:
LocalDateTime dt = LocalDateTime.of(2020, 1, 2, 12, 34, 56);
PreparedStatement ps = conn.prepareStatement(
"insert into t1 (id, a) values (?, ?)"
);
int id = 1;
ps.setInt(1, id);
ps.setObject(2, dt); // fails here
ps.execute();
I can see it doesn't even get to the ps.execute()
method. I've read that a JDBC 4.2 driver may fix this, but I can't find it anywhere.