Skip to content

Flag setTimestamp, getTimestamp, setObject(.., Timestamp), setObject(.., Date) and similar JDBC methods #5291

@vlsi

Description

@vlsi

Most of the modern databases (all of them?) support both timestamp and timestamp with time zone.
In that regard, setTimestamp(..., java.sql.Timestamp) becomes ambiguous, and the driver has to guess if the user meant with or without timezone.

I suggest the applications should use java.time APIs, then the JDBC driver would get a clear view on the intention of the user.

For instance:

  • java.time.LocalDate -> date
  • java.time.LocalTime -> time
  • java.time.LocalDateTime -> timestamp
  • java.time.OffsetDateTime -> timestamp with time zone
  • ...

Problematic APIs

  • PreparedStatement#setDate
  • PreparedStatement#setTime
  • PreparedStatement#setTimestamp
  • PreparedStatement#setObject(..., java.util.Date,...)
  • PreparedStatement#setObject(..., java.sql.Date,...)
  • PreparedStatement#setObject(..., java.sql.Time,...)
  • PreparedStatement#setObject(..., java.sql.Timestamp,...)
  • PreparedStatement#setTime
  • PreparedStatement#setTimestamp
  • ResultSet#getDate
  • ResultSet#getTime
  • ResultSet#getTimestamp
  • CallableStatement#getDate
  • CallableStatement#getTime
  • CallableStatement#getTimestamp

PS. I'm https://github.com/pgjdbc/pgjdbc co-maintainer, and I contributed to time-related tests and bugfixes. Frankly, I believe JDBC java.sql. time-related types are error-prone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions