Код: Выделить всё
create table timestamp_test
(
id bigserial primary key,
ts_col timestamp with time zone
);
insert into timestamp_test(ts_col)
values (now());
Код: Выделить всё
private final static String selectQuery = "select * from timestamp_test";
@Test
public void jdbcOffsetDateTimeTest()
{
try (Connection conn = dataSource.getConnection())
{
PreparedStatement ps = conn.prepareStatement(selectQuery,
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = ps.executeQuery();
rs.next();
rs.updateObject("ts_col", OffsetDateTime.now());
rs.updateRow();
rs.close();
ps.close();
} catch (SQLException e)
{
log.error("Exception: {}", e.getMessage(), e);
}
}
Код: Выделить всё
java.lang.ClassCastException: class java.time.OffsetDateTime cannot be cast to class java.sql.Timestamp (java.time.OffsetDateTime is in module java.base of loader 'bootstrap'; java.sql.Timestamp is in module java.sql of loader 'platform')
at org.postgresql.jdbc.PgResultSet.setRowBufferColumn(PgResultSet.java:2128)
at org.postgresql.jdbc.PgResultSet.updateRowBuffer(PgResultSet.java:2165)
at org.postgresql.jdbc.PgResultSet.updateRow(PgResultSet.java:1643)
at com.zaxxer.hikari.pool.ProxyResultSet.updateRow(ProxyResultSet.java:69)
at com.zaxxer.hikari.pool.HikariProxyResultSet.updateRow(HikariProxyResultSet.java)
at st.notexi.springtest.DbTest.jdbcOffsetDateTimeTest(DbTest.java:116)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Код: Выделить всё
rs.updateObject("some_timestampz_column", new Timestamp(myOffsetDateTimeInstance.toEpochSecond() * 1000));
Подробнее здесь: https://stackoverflow.com/questions/792 ... atetime-to