Skip to main content
added 99 characters in body
Source Link
Basil Bourque
  • 346.7k
  • 130
  • 950
  • 1.3k

No need to convert

Like others have said in comments, PostgreSQL's JDBC hasdriver now supports JDBC 4.2 including Java 8 Time API support. We can exchange java.time objects directly with the database.

https://jdbc.postgresql.org/documentation/head/8-date-time.html

So no need to convert, no need to ever use the java.sql types againagain. Use only their replacements in the java.time package as shown in this list.

PostgreSQL™ Java SE 8 (java.time) DATE LocalDate TIME [ WITHOUT TIMEZONE ] LocalTime TIMESTAMP [ WITHOUT TIMEZONE ] LocalDateTime TIMESTAMP WITH TIMEZONE OffsetDateTime or Instant 

This can be retrieved via ResultSet::getObject

ResultSet rs = ...; while (rs.next()) { LocalDate localDate = rs.getObject(1, LocalDate.class)); } 

Store a java.time object by calling PreparedStatement::setObject.

myPreparedStatement.setObject( … , myInstant ) ; 

No need to convert

Like others have said in comments, PostgreSQL's JDBC has Java 8 Time API support.

https://jdbc.postgresql.org/documentation/head/8-date-time.html

So no need to convert, no need to ever use the java.sql types again. Use only their replacements in the java.time package as shown in this list.

PostgreSQL™ Java SE 8 (java.time) DATE LocalDate TIME [ WITHOUT TIMEZONE ] LocalTime TIMESTAMP [ WITHOUT TIMEZONE ] LocalDateTime TIMESTAMP WITH TIMEZONE OffsetDateTime or Instant 

This can be retrieved via ResultSet::getObject

ResultSet rs = ...; while (rs.next()) { LocalDate localDate = rs.getObject(1, LocalDate.class)); } 

Store a java.time object by calling PreparedStatement::setObject.

myPreparedStatement.setObject( … , myInstant ) ; 

No need to convert

Like others have said in comments, PostgreSQL's JDBC driver now supports JDBC 4.2 including Java 8 Time API support. We can exchange java.time objects directly with the database.

https://jdbc.postgresql.org/documentation/head/8-date-time.html

So no need to convert, no need to ever use the java.sql types again. Use only their replacements in the java.time package as shown in this list.

PostgreSQL™ Java SE 8 (java.time) DATE LocalDate TIME [ WITHOUT TIMEZONE ] LocalTime TIMESTAMP [ WITHOUT TIMEZONE ] LocalDateTime TIMESTAMP WITH TIMEZONE OffsetDateTime or Instant 

This can be retrieved via ResultSet::getObject

ResultSet rs = ...; while (rs.next()) { LocalDate localDate = rs.getObject(1, LocalDate.class)); } 

Store a java.time object by calling PreparedStatement::setObject.

myPreparedStatement.setObject( … , myInstant ) ; 
added 138 characters in body; added 29 characters in body
Source Link
Basil Bourque
  • 346.7k
  • 130
  • 950
  • 1.3k

No need to convert

Like others have said in comments, PostgreSQL's JDBC has Java 8 Time API support.

https://jdbc.postgresql.org/documentation/head/8-date-time.html

So no need to convert, no need to ever use the java.sql types again. Use only their replacements in the java.time package as shown in this list.

PostgreSQL™ Java SE 8 (java.time) DATE LocalDate TIME [ WITHOUT TIMEZONE ] LocalTime TIMESTAMP [ WITHOUT TIMEZONE ] LocalDateTime TIMESTAMP WITH TIMEZONE OffsetDateTime 
PostgreSQL™ Java SE 8 (java.time) DATE LocalDate TIME [ WITHOUT TIMEZONE ] LocalTime TIMESTAMP [ WITHOUT TIMEZONE ] LocalDateTime TIMESTAMP WITH TIMEZONE OffsetDateTime or Instant 

This can be retrieved via ResultSet::getObject

ResultSet rs = ...; while (rs.next()) { LocalDate localDate = rs.getObject(1, LocalDate.class)); } 

Store a java.time object by calling PreparedStatement::setObject.

myPreparedStatement.setObject( … , myInstant ) ;  

No need to convert

Like others have said in comments, PostgreSQL's JDBC has Java 8 Time API support.

https://jdbc.postgresql.org/documentation/head/8-date-time.html

So no need to convert, no need to ever use the java.sql types again. Use only their replacements in the java.time package as shown in this list.

PostgreSQL™ Java SE 8 (java.time) DATE LocalDate TIME [ WITHOUT TIMEZONE ] LocalTime TIMESTAMP [ WITHOUT TIMEZONE ] LocalDateTime TIMESTAMP WITH TIMEZONE OffsetDateTime 

This can be retrieved via ResultSet::getObject

ResultSet rs = ...; while (rs.next()) { LocalDate localDate = rs.getObject(1, LocalDate.class)); } 

No need to convert

Like others have said in comments, PostgreSQL's JDBC has Java 8 Time API support.

https://jdbc.postgresql.org/documentation/head/8-date-time.html

So no need to convert, no need to ever use the java.sql types again. Use only their replacements in the java.time package as shown in this list.

PostgreSQL™ Java SE 8 (java.time) DATE LocalDate TIME [ WITHOUT TIMEZONE ] LocalTime TIMESTAMP [ WITHOUT TIMEZONE ] LocalDateTime TIMESTAMP WITH TIMEZONE OffsetDateTime or Instant 

This can be retrieved via ResultSet::getObject

ResultSet rs = ...; while (rs.next()) { LocalDate localDate = rs.getObject(1, LocalDate.class)); } 

Store a java.time object by calling PreparedStatement::setObject.

myPreparedStatement.setObject( … , myInstant ) ;  
added 162 characters in body; added 22 characters in body
Source Link
Basil Bourque
  • 346.7k
  • 130
  • 950
  • 1.3k

No need to convert

Like others have said in comments., PostgreSQL's JDBC has Java 8 Time API support.

https://jdbc.postgresql.org/documentation/head/8-date-time.html

So no need to convert, no need to ever use the java.sql types again. Use only their replacements in the java.time package as shown in this list.

PostgreSQL™ Java SE 8 (java.time) DATE LocalDate TIME [ WITHOUT TIMEZONE ] LocalTime TIMESTAMP [ WITHOUT TIMEZONE ] LocalDateTime TIMESTAMP WITH TIMEZONE OffsetDateTime 

This can be retrieved via ResultSet::getObject

ResultSet rs = ...; while (rs.next()) { LocalDate localDate = rs.getObject(1, LocalDate.class)); } 

Like others have said in comments. PostgreSQL's JDBC has Java 8 Time API support.

https://jdbc.postgresql.org/documentation/head/8-date-time.html

PostgreSQL™ Java SE 8 DATE LocalDate TIME [ WITHOUT TIMEZONE ] LocalTime TIMESTAMP [ WITHOUT TIMEZONE ] LocalDateTime TIMESTAMP WITH TIMEZONE OffsetDateTime 

This can be retrieved via ResultSet::getObject

ResultSet rs = ...; while (rs.next()) { LocalDate localDate = rs.getObject(1, LocalDate.class)); } 

No need to convert

Like others have said in comments, PostgreSQL's JDBC has Java 8 Time API support.

https://jdbc.postgresql.org/documentation/head/8-date-time.html

So no need to convert, no need to ever use the java.sql types again. Use only their replacements in the java.time package as shown in this list.

PostgreSQL™ Java SE 8 (java.time) DATE LocalDate TIME [ WITHOUT TIMEZONE ] LocalTime TIMESTAMP [ WITHOUT TIMEZONE ] LocalDateTime TIMESTAMP WITH TIMEZONE OffsetDateTime 

This can be retrieved via ResultSet::getObject

ResultSet rs = ...; while (rs.next()) { LocalDate localDate = rs.getObject(1, LocalDate.class)); } 
Source Link
skrueger
  • 306
  • 3
  • 6
Loading