S - source type in JDBCT - target type in Time4Jpublic abstract class JDBCAdapter<S,T> extends TemporalType<S,T>
Serves as bridge to temporal types in JDBC.
All singleton instances are defined as static constants and are immutable.
| Modifier and Type | Field and Description |
|---|---|
static JDBCAdapter<Date,PlainDate> |
SQL_DATE
Bridge between a JDBC-Date and the class
PlainDate. |
static JDBCAdapter<Time,PlainTime> |
SQL_TIME
Bridge between a JDBC-Time and the class
PlainTime. |
static JDBCAdapter<Timestamp,PlainTimestamp> |
SQL_TIMESTAMP
Bridge between a JDBC-Timestamp and the class
PlainTimestamp. |
static JDBCAdapter<Timestamp,Moment> |
SQL_TIMESTAMP_WITH_ZONE
Bridge between a JDBC-Timestamp and the class
Moment. |
CLOCK, INSTANT, JAVA_UTIL_CALENDAR, JAVA_UTIL_DATE, JAVA_UTIL_TIMEZONE, LOCAL_DATE, LOCAL_DATE_TIME, LOCAL_TIME, MILLIS_SINCE_UNIX, THREETEN_DURATION, THREETEN_PERIOD, ZONED_DATE_TIMEpublic static final JDBCAdapter<Date,PlainDate> SQL_DATE
Bridge between a JDBC-Date and the class PlainDate.
If the system property "net.time4j.sql.utc.conversion" is set to the value "true" then the conversion will not take into account the system timezone anticipating that a SQL-DATE was created without any timezone calculation on the server side, too. That is more or less the case if UTC is the default timezone on the application server.
Example (UTC as default timezone):
java.sql.Date sqlValue = new java.sql.Date(86400 * 1000); PlainDate date = JDBCAdapter.SQL_DATE.translate(sqlValue); System.out.println(date); // output: 1970-01-02
Note: The conversion is only possible if a date has
a year in the range 1900-9999 because else a JDBC-compatible
database cannot store the date per SQL-specification. It is strongly
recommended to interprete a SQL-DATE only as abstract JDBC object
because its text output via java.sql.Date.toString()-method
is not reliable (dependency on the gregorian-julian cutover day
+ possible timezone side effects). The concrete formatting can be
done by Time4J for example via PlainDate.toString() or a
suitable ChronoFormatter.
public static final JDBCAdapter<Time,PlainTime> SQL_TIME
Bridge between a JDBC-Time and the class PlainTime.
If the system property "net.time4j.sql.utc.conversion" is set to the value "true" then the conversion will NOT take into account the system timezone anticipating that a SQL-DATE was created without any timezone calculation on the server side, too. That is more or less the case if UTC is the default timezone on the application server.
Example (UTC as default timezone):
java.sql.Time sqlValue = new java.sql.Time(43200 * 1000); PlainTime time = JDBCAdapter.SQL_TIME.translate(sqlValue); System.out.println(time); // output: T12:00:00
Note: The conversion only occurs in millisecond
precision at best not in in nanosecond precision so there is possible
loss of data. Furthermore, the text output via the method
java.sql.Time.toString() can be misinterpreted by timezone
side effects. Concrete text output should be done by Time4J.
public static final JDBCAdapter<Timestamp,PlainTimestamp> SQL_TIMESTAMP
Bridge between a JDBC-Timestamp and the class PlainTimestamp.
If the system property "net.time4j.sql.utc.conversion" is set to the value "true" then the conversion will NOT take into account the system timezone anticipating that a SQL-DATE was created without any timezone calculation on the server side, too. That is more or less the case if UTC is the default timezone on the application server.
Example (UTC as default timezone):
java.sql.Timestamp sqlValue = new java.sql.Timestamp(86401 * 1000); sqlValue.setNanos(1); PlainTimestamp ts = JDBCAdapter.SQL_TIMESTAMP.translate(sqlValue); System.out.println(ts); // output: 1970-01-02T00:00:01,000000001
public static final JDBCAdapter<Timestamp,Moment> SQL_TIMESTAMP_WITH_ZONE
Bridge between a JDBC-Timestamp and the class Moment.
Notes: Leap seconds are not storable. And the maximum available
precision is dependent on the database. Despite of the misleading SQL name,
this conversion does not use a timezone but a timezone offset, finally
ZonalOffset.UTC.
Copyright © 2014–2017. All rights reserved.