Reputation: 167
I'm currently upgrading an application that uses DB2/400 database, and I'm migrating to the new java time api (LocalDate, LocalTime, ...), using the latest version of jt400.jar.
However, when executing statement setObject as follows
stmt.setObject(++columns, LocalDate.now());
I'm getting this exception
Thread[main,5,main] Ter jan 18 10:46:56:852 GMT 2022 as400: PreparedStatementImpl STMT0001 (1588970020) : setObject().
Thread[main,5,main] Ter jan 18 10:46:56:852 GMT 2022 as400: PreparedStatementImpl STMT0001 (1588970020) : parameter index: 2 type: java.time.LocalDate toString():2022-01-18.
Thread[main,5,main] Ter jan 18 10:46:56:853 GMT 2022 as400: Unknown com.ibm.as400.access.SQLDate@3c679bde (1013423070) : Unable to assign object(2022-01-18) of class(class java.time.LocalDate).
Thread[main,5,main] Ter jan 18 10:46:56:853 GMT 2022 as400: Unknown com.ibm.as400.access.SQLDate@3c679bde (1013423070) : Throwing exception, sqlState: 07006 reason: Data type mismatch. vendor code -99999.java.sql.SQLException: Data type mismatch.
at com.ibm.as400.access.JDError.createSQLExceptionSubClass(JDError.java:891)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:436)
at com.ibm.as400.access.SQLDate.set(SQLDate.java:452)
at com.ibm.as400.access.AS400JDBCPreparedStatementImpl.setValue(AS400JDBCPreparedStatementImpl.java:3655)
at com.ibm.as400.access.AS400JDBCPreparedStatementImpl.setObject(AS400JDBCPreparedStatementImpl.java:3124)
at mypackage.jdbc.LocalDateTester.main(LocalDateTester.java:26)
Also, when trying to read from the DB using
rs.getObject(2, LocalDate.class)
I'm also getting the exception
Exception in thread "main" java.sql.SQLException: Data type not valid.
at com.ibm.as400.access.JDError.createSQLExceptionSubClass(JDError.java:985)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:436)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:413)
at com.ibm.as400.access.AS400JDBCResultSet.getObject(AS400JDBCResultSet.java:7457)
at mypackage.jdbc.LocalDateTester.main(LocalDateTester.java:47)
The DB column type on iSeries is Date.
I'm I doing something wrong, or is the new java.time api not supported?
If so, does anyone know if there are any plans for Java Time API support?
Thanks in advance
Upvotes: 0
Views: 334
Reputation: 1074
You must use java.sql.date with JDBC. Convert with :
java.sql.Date.valueOf(LocalDate.now());
Upvotes: 1