db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <knut.hat...@oracle.com>
Subject Re: JSR310 and JDBC 4.2
Date Wed, 29 Oct 2014 07:39:19 GMT
gquintana <gerald.quintana@gmail.com> writes:

> From documentation, Derby is supposed to implement JDBC4.2 which introduces
> JSR 310 (Date & Time API) support into JDBC (among other things).
>
> Reading http://openjdk.java.net/jeps/170, I would have thought the following
> code would work, but it doesn't:
>
> LocalDate birthDate = ....
> statement.setObject(5, birthDate, Types.DATE);
>
> Caused by: ERROR XCL12: Une tentative de placement d'une valeur de données de type 'java.time.LocalDate'
dans une valeur de données de type 'DATE' a été effectuée.
> 	at org.apache.derby.client.am.CrossConverters.setObject(Unknown Source)
> 	at org.apache.derby.client.am.ClientPreparedStatement.setObjectX(Unknown Source)
> 	... 52 more
>
>
> LocalDate birthDate=resultSet.getObject("birth_date", LocalDate.class);
>
> Caused by: ERROR 22005: Une tentative d'obtention d'une valeur de données de type 'java.time.LocalDate'
à partir d'une valeur de données de type 'DATE' a été effectuée.
> 	... 66 more
>
>
>
> What's the supposed way of reading/writing JSR 310 types from/into JDBC
> database?

Derby doesn't support the new type mappings yet. There is a JIRA issue
that tracks it (https://issues.apache.org/jira/browse/DERBY-6445), but
there hasn't been any activity yet.

For now, you'll have to convert JSR 310 time and date values to the
corresponding classes in the java.sql package yourself. For example:

statement.setDate(5, java.sql.Date.valueOf(birthDate));

...

LocalDate birthDate = resultSet.getDate("birth_date").toLocalDate();


Hope this helps,

-- 
Knut Anders

Mime
View raw message