We are using JDBC driver to connect to Snowflake and perform inserts. While working with TIME datatype, we provide time value as 10:10:10 with setTime in insert and when retrieved with getTime, we get 02:10:10.
The documentation says - TIME internally stores “wallclock” time, and all operations on TIME values are performed without taking any time zone into consideration.
Why this conversion? How to make sure we get back what we inserted?
Sample program -
try (Connection con = getConnection()) {
try (PreparedStatement ps = con.prepareStatement("insert into Test_Time values (?)")) {
ps.setTime('10:10:10');
ps.executeUpdate();
}
try (Statement statement = con.createStatement()) {
try (ResultSet resultSet = statement.executeQuery("select * from Test_Time ")) {
while (resultSet.next()) {
System.out.println(resultSet.getTime(1));
}
}
}
}
We tried both -
ps.setTime(Time.valueOf('10:10:10'))
ps.setTime('10:10:10')
When similar is tried from WEB portal worksheet, we see the same inserted value 10:10:10. Web portal able to show the right desired result so wondering Is there anything basic missing in my case?
Thank you for help in advance.
Update - Done more testing around this - found there is no difference between "setTime(int idx, Time t)" and "setTime(int idx, Time t, Calendar c)". If you already know the timezone of your data then there is no way to supply custom timezone.