The LightDB JDBC driver implements native support for the Java 8 Date and Time API (JSR-310) using JDBC 4.2.
Table 5.1. Supported Java 8 Date and Time classes
LightDB | Java SE 8 |
---|---|
DATE | LocalDate |
TIME [ WITHOUT TIME ZONE ] | LocalTime |
TIMESTAMP [ WITHOUT TIME ZONE ] | LocalDateTime |
TIMESTAMP WITH TIME ZONE | OffsetDateTime |
This is closely aligned with tables B-4 and B-5 of the JDBC 4.2
specification. Note that ZonedDateTime
,
Instant
and OffsetTime / TIME WITH TIME ZONE
are not supported. Also note that all OffsetDateTime
instances will have be in UTC (have offset 0). This is because the
backend stores them as UTC.
Example 5.2. Reading Java 8 Date and Time values using JDBC
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM mytable WHERE columnfoo = 500");
while (rs.next())
{
System.out.print("Column 1 returned ");
= rs.getObject(1, LocalDate.class));
LocalDate localDate System.out.println(localDate);
}
.close();
rs.close(); st
For other data types simply pass other classes to
#getObject
. Note that the Java data types needs to match
the SQL data types in table 7.1.
Example 5.3. Writing Java 8 Date and Time values using JDBC
= LocalDate.now();
LocalDate localDate PreparedStatement st = conn.prepareStatement("INSERT INTO mytable (columnfoo) VALUES (?)");
.setObject(1, localDate);
st.executeUpdate();
st.close(); st