Reputation:
After having some issues with using date types (mostly with timestampt / timestamptz) I've relalized, that I don't know the basics.
How are the date types handled by the official JDBC driver?
What is actually sent to the DB?
I've assumed, that the Date types are converted to the text representation, using either system locale, or given locale, if specified as extra parameters. The results of JDBC queries should be then identical with what I get when I log with PSQL and test the queries pasting them as text.
How are those values processed by the JDBC driver? I guess most gotschas are caused by not knowing that part. I think I know quite well how Java handle dates, and how PostgreSQL handle dates. The problem is that JDBC black box between them.
Upvotes: 1
Views: 232
Reputation: 24453
A mapping of the JSR 310 types to the SQL types is provided in documentation Table 5.1.
Inspecting PostgreSQL JDBC Driver PgPreparedStatement.setObject() method we can see that each Java type is used to set a timestamp, for example:
case Types.TIMESTAMP_WITH_TIMEZONE:
if (in instanceof java.time.OffsetDateTime) {
setTimestamp(parameterIndex, (java.time.OffsetDateTime) in);
Internally this is calling TimestampUtils.toString() which is converting a date-time to a string.
Upvotes: 1