Error: No row available for wasNull.

14 views
Skip to first unread message

Pierre Vacher

unread,
Sep 16, 2024, 10:00:18 AM9/16/24
to firebird-java
Hi all,

On a ResultSet I would like to reread the values ​​of a new row that I inserted with updateXXX() (ie: after having made a moveToInsertRow()). I can do it with getXXX() but after that I do not have access to the wasNull() method without the message: No row available for wasNull.

Normally it is possible to access the values ​​on the insert row by the getters of the ResultSet (ie: getXXX()) before validating the insert by insertRow()  so why I can't know if the value is null?

Thanks in advance,

Pierre.

Mark Rotteveel

unread,
Sep 16, 2024, 1:31:36 PM9/16/24
to firebi...@googlegroups.com
On 16/09/2024 16:00, Pierre Vacher wrote:
> On a ResultSet I would like to reread the values ​​of a new rowthat I
> inserted with updateXXX()(ie: after having made amoveToInsertRow()). I
> can do it with getXXX() but after that I do not have access to the
> wasNull() method without the message: *No row available for wasNull*.
>
> Normally it is possible to access the values ​​on the insert row by the
> getters of the ResultSet (ie: getXXX()) before validating the insert by
> insertRow() so why I can't know if the value is null?

Can you provide a simple program the reproduces the issue?

Mark
--
Mark Rotteveel

Pierre Vacher

unread,
Sep 17, 2024, 4:43:26 AM9/17/24
to firebird-java
Hi Mark,

Here is the code that allows me to reproduce:


    public void testWasNull(java.sql.Connection connection) {
        String select = "select * from t1";
        try {
            populateTable(connection);

            java.sql.PreparedStatement ps = connection.prepareStatement(select,
                                                                        java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
                                                                        java.sql.ResultSet.CONCUR_UPDATABLE);

            java.sql.ResultSet rs = ps.executeQuery();

            rs.moveToInsertRow();
            rs.updateNull(1);
            rs.updateString(2, "s10");

            for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
                Object value = rs.getObject(i);
                if (rs.wasNull()) {
                    System.out.println("SensitiveResultSet.testWasNull() Value was Null");
                }
                else {
                    System.out.println("SensitiveResultSet.testWasNull() Value: " + value.toString());
                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    void populateTable(java.sql.Connection connection) throws SQLException {
        java.sql.Statement statement = connection.createStatement();
        //statement.execute("drop table t1 if exists");
        statement.execute("create table t1 (i int primary key, v varchar(10))");
        statement.close();

        String insert = "insert into t1 values(?, ?)";
        java.sql.PreparedStatement ps = connection.prepareStatement(insert);

        for (int i = 0; i < 10; i++) {
            ps.setInt(1, i);
            ps.setString(2, String.valueOf(i) + " s");
            ps.execute();
        }

        ps.close();
    }

And here is the error message:

java.sql.SQLException: No row available for wasNull.
        at org.firebirdsql.jdbc.FBResultSet.wasNull(FBResultSet.java:465)
        at io.github.prrvchr.jdbcdriver.resultset.SensitiveResultSet.testWasNull(SensitiveResultSet.java:117)
        at io.github.prrvchr.jdbcdriver.resultset.SensitiveResultSet.<init>(SensitiveResultSet.java:96)
        at io.github.prrvchr.jdbcdriver.resultset.ResultSetHelper.getResultSet(ResultSetHelper.java:77)
        at io.github.prrvchr.uno.sdbcx.RowSetSuper.<init>(RowSetSuper.java:69)
        at io.github.prrvchr.uno.sdb.RowSet.<init>(RowSet.java:58)
        at io.github.prrvchr.uno.sdb.PreparedStatement.getResultSet(PreparedStatement.java:93)
        at io.github.prrvchr.uno.sdbc.PreparedStatementMain.executeQuery(PreparedStatementMain.java:404)


Regards,

Pierre.

Mark Rotteveel

unread,
Sep 17, 2024, 5:06:30 AM9/17/24
to firebi...@googlegroups.com
Thanks, I'll look into it.

As an aside, wasNull() is primarily intended for null checks when
retrieving primitive values (as those report the "default" value of
0/0.0/false for NULL). If you use an object result (like returned by
getObject(..)), the nullness will also be reported by the value being
null. So, as a workaround, you can use `if (value == null)` instead of
`if (rs.wasNull())`.

Mark
--
Mark Rotteveel

Mark Rotteveel

unread,
Sep 17, 2024, 5:46:31 AM9/17/24
to firebi...@googlegroups.com
I created issue https://github.com/FirebirdSQL/jaybird/issues/816 for this.

Mark
--
Mark Rotteveel

Mark Rotteveel

unread,
Sep 17, 2024, 7:03:27 AM9/17/24
to firebi...@googlegroups.com
On 17/09/2024 11:46, 'Mark Rotteveel' via firebird-java wrote:
> I created issue https://github.com/FirebirdSQL/jaybird/issues/816 for this.

I have implemented a fix, it can be tested against the latest
5.0.6.java8-SNAPSHOT, 5.0.6.java11-SNAPSHOT and 6.0.0-SNAPSHOT (from
https://oss.sonatype.org/content/repositories/snapshots/).

Mark
--
Mark Rotteveel

Pierre Vacher

unread,
Sep 17, 2024, 7:17:40 PM9/17/24
to firebird-java
Thanks for the fix Mark, however I can't find the archive, only the sources and the docs?

Mark Rotteveel

unread,
Sep 18, 2024, 3:10:11 AM9/18/24
to firebi...@googlegroups.com
On 18/09/2024 01:17, Pierre Vacher wrote:
> Thanks for the fix Mark, however I can't find the archive, only the
> sources and the docs?

They are there. Use Maven (configured with the snapshot repository) to
get the snapshot version, it will automatically select the right version
for you.

In any case, at this moment the latest snapshots are:

5.0.6.java8-SNAPSHOT:
https://oss.sonatype.org/content/repositories/snapshots/org/firebirdsql/jdbc/jaybird/5.0.6.java8-SNAPSHOT/jaybird-5.0.6.java8-20240917.105744-4.jar

5.0.6.java11-SNAPSHOT:
https://oss.sonatype.org/content/repositories/snapshots/org/firebirdsql/jdbc/jaybird/5.0.6.java11-SNAPSHOT/jaybird-5.0.6.java11-20240917.105835-4.jar

6.0.0-SNAPSHOT:
https://oss.sonatype.org/content/repositories/snapshots/org/firebirdsql/jdbc/jaybird/6.0.0-SNAPSHOT/jaybird-6.0.0-20240917.105941-33.jar

Mark
--
Mark Rotteveel

Pierre Vacher

unread,
Sep 19, 2024, 6:33:42 PM9/19/24
to firebird-java
Thanks Mark for those links, I wasn't looking in the right place.

I confirm that this problem is resolved but on the other hand I have just opened a new issue concerning ResultSet insertion.

And congratulations for your speed, it takes me longer than you to identify the origin of my problems.

Regards,

Pierre.

Reply all
Reply to author
Forward
0 new messages