I am aware that JDBC 4.2 drivers support reading and writing java.time objects. I tried storing and retrieving an Instant object using MariaDB 2.6 driver. I am using Apache Commons DB Utils to run the queries.
I can store the Instants just fine, but not able to retrieve them. Is this a bug with the driver or am I doing something wrong?
Storing & reading code
String sql = "insert into TimeTest(time) values(?)";
Instant ts = Instant.from(Instant.now());
sqlQueryRunner.update(dbConnection,sql, ts);
ResultSetHandler<Instant[]> h = new ResultSetHandler<Instant[]>() {
public Instant[] handle(ResultSet rs) throws SQLException {
if (!rs.next()) {
return null;
}
ResultSetMetaData meta = rs.getMetaData();
int cols = meta.getColumnCount();
Instant[] result = new Instant[cols];
for (int i = 0; i < cols; i++) {
**//Does not work**
//result[i] = rs.getObject(i+1, Instant.class);
**//works fine**
result[i] = rs.getObject(i+1, Timestamp.class).toInstant();
}
return result;
}
};
The TimeTest is a table having a datetime field time:
CREATE TABLE `TimeTest` (
`time` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Error when reading Instant
Caused by: java.sql.SQLException: Type class 'java.time.Instant' is not supported