You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Martijn Blankestijn <ma...@gmail.com> on 2014/01/02 18:05:01 UTC
JDK 8 and setObject
Hi,
I am using DERBY: "10.10.1.2", packaged with Java 8 JDK
("java.runtime.version=1.8.0-ea-b120").
I created a table in-memory: create table Persoon (id int not null
GENERATED ALWAYS AS IDENTITY , datum date not null, tijd time not null,
tijdstip timestamp not null)
When I use the following code:
try (PreparedStatement preparedStatement =
connection.prepareStatement("insert into Persoon (datum, tijd, tijdstip)
values (?,?,?)")) {
preparedStatement.setObject(1, LocalDate.of(2014, 3, 20),
JDBCType.DATE);
I get the following exception:
java.sql.SQLDataException: An attempt was made to get a data value of type
'DATE' from a data value of type 'java.time.LocalDate'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown
Source)
at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(Unknown
Source)
at
org.apache.derby.impl.jdbc.EmbedPreparedStatement.dataTypeConversion(Unknown
Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.setObject(Unknown
Source)
at
nl.ordina.jdk8.TimePersistenceTest.insertParameterSetObject(TimePersistenceTest.java:48)
If I skip the JDBCType.Date, I get the same error.
In the "JDBC Maintenance Release 4.2" proposed changes the following is
written
"21 Add the following mapping to table B-4, Mapping from Java Objects to
JDBC Types
• Map the Java Object Type javax.time.LocalDate to the JDBC Type DATE
22 Add the following mapping to table B-5, Mapping, conversions Performed
by setObject and setNull between
Java Object Types
• Allow the conversion of javax.time.LocalDate to CHAR, VARCHAR,
LONGVARCHAR, and DATE"
Am I missing something?
Regards,
Martijn Blankestijn
Re: JDK 8 and setObject
Posted by Knut Anders Hatlen <kn...@oracle.com>.
Martijn Blankestijn <ma...@gmail.com> writes:
> In the "JDBC Maintenance Release 4.2" proposed changes the following
> is written
>
> "21 Add the following mapping to table B-4, Mapping from Java Objects
> to JDBC Types
> • Map the Java Object Type javax.time.LocalDate to the JDBC Type DATE
>
> 22 Add the following mapping to table B-5, Mapping, conversions
> Performed by setObject and setNull between
> Java Object Types
> • Allow the conversion of javax.time.LocalDate to CHAR, VARCHAR,
> LONGVARCHAR, and DATE"
>
> Am I missing something?
Hi Martijn,
I think the LocalDate class was added to Java 8 after JDBC 4.2 support
was added to Derby, and we've apparently overlooked that these new
mappings were added to a later revision of the specification.
I've filed a JIRA issue to get the new mappings added to Derby:
https://issues.apache.org/jira/browse/DERBY-6445
Thanks,
--
Knut Anders
Re: JDK 8 and setObject
Posted by Bryan Pendleton <bp...@gmail.com>.
> java.sql.SQLDataException: An attempt was made to get a data value of type 'DATE' from a data value of type 'java.time.LocalDate'.
According to
http://download.java.net/jdk8/docs/api/java/sql/Date.html
http://download.java.net/jdk8/docs/api/java/util/Date.html
and
http://download.java.net/jdk8/docs/api/java/time/LocalDate.html
a java.sql.Date is a sub-class of java.util.Date, but a java.time.LocalDate
has no relationship to either of the above.
I don't see any information in the LocalDate JavaDoc that says
anything implying that a java.time.LocalDate is supposed to
be in any way interoperable with the java.util.Date class.
Is this the question you are asking?
thanks,
bryan