I have observed that java cachedrowset.updateDate(null) or cachedrowset.updateNull(DateColumn) does not work. It always gets error. I tried this on an apache derby database version 16.1 on a nullable Date column. Does anybody experience this error? I am using openjdk 17. I think this is a bug.
I tried to use statement.execute(query). The underlying nullable Date column of my apache derby 16.1 database can be set to null if i update it by executing statement.execute(). but not with cachedrowset.updatexxx(). Can anybody please help me.
**This is just a part of my code:**
JDBC_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
private CachedRowSet cached_RowSet;
RowSetFactory myRowSetFactory;
**This is my code that creates the CachedRowSet object:**
myRowSetFactory = RowSetProvider.newFactory();
cached_RowSet = myRowSetFactory.createCachedRowSet();
cached_RowSet.setTableName("PROJECTS"); // it is necessary to setTableName equal to the table being queried, in order to update the cached rowset
// CachedRowSetImpl crs = new CachedRowSetImpl(); this does not work.
cached_RowSet.setUrl(DATABASE_URL);
cached_RowSet.setUsername(USERNAME);
cached_RowSet.setPassword(PASSWORD);
int [] keys = {1};
cached_RowSet.setKeyColumns(keys);
cached_RowSet.setConcurrency(ResultSet.CONCUR_UPDATABLE );
cached_RowSet.setCommand(strQuery);
cached_RowSet.execute();
**This is the code that updates to Null the Nullable Date Column in Apache Derby:**
cached_RowSet.absolute(row + 1);
cached_RowSet.updateDate("NullableDateColumn", null); --> gets error
cached_RowSet.updateNull("NullableDateColumn"); --> gets error
cached_RowSet.updateRow();
cached_RowSet.acceptChanges();
**This is the error that i get:**
java.sql.SQLDataException: 22005 : [0] DATE, [1] INTEGER
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:84)
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:141)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Util.java:225)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Util.java:220)
at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(EmbedConnection.java:3208)
at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(ConnectionChild.java:153)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.dataTypeConversion(EmbedPreparedStatement.java:1714)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.setNull(EmbedPreparedStatement.java:345)
at java.sql.rowset/com.sun.rowset.internal.CachedRowSetWriter.updateOriginalRow(CachedRowSetWriter.java:752)
at java.sql.rowset/com.sun.rowset.internal.CachedRowSetWriter.writeData(CachedRowSetWriter.java:366)
at java.sql.rowset/com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:898) ........ xxxxxxxxx
**But, I can use this:**
cached_RowSet.updateNull("NullableDoubleColumn"); --> this is ok!
cached_RowSet.updateNull("NullableVarCharColumn"); --> this is ok!
cached_RowSet.updateNull("NullableIntegerColumn"); --> this is ok!
cached_RowSet.updateDate("NullableDateColumn",java.sql.Date.valueOf("2023-05-18")); --> this is ok!
I mean the CachedRowSet object can update to Null every other nullable column but not the nullable date column.
I really think this is a bug. Is this a bug?
I am using Apache Derby Database 16.1 and OpenJDK 17.
7