nlowe
nlowe

Reputation: 1039

Unable to view recently inserted results in H2

I'm using the H2 Database system for a small java project I'm working on. If I manually run the Queries, everything works as expected, but when I run my program, I get the following:

Constructed: INSERT INTO library VALUES (null,'TEMPORARY_EFFECT_1369614387100','asdf',0,0,0,0,0)
Constructed: SELECT id FROM library WHERE name='TEMPORARY_EFFECT_1369614387100'
org.h2.jdbc.JdbcSQLException: No data is available [2000-171]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
    at org.h2.message.DbException.get(DbException.java:169)
    at org.h2.message.DbException.get(DbException.java:146)
    at org.h2.message.DbException.get(DbException.java:135)
    at org.h2.jdbc.JdbcResultSet.checkOnValidRow(JdbcResultSet.java:2956)
    at org.h2.jdbc.JdbcResultSet.get(JdbcResultSet.java:2962)
    at org.h2.jdbc.JdbcResultSet.getInt(JdbcResultSet.java:306)

I'm not exactly sure what is going on. According to the JavaDocs for JDBC and H2, I'm doing things right (I think). The INSERT is executed by calling db.createStatement().executeUpdate(...) and the SELECT via db.prepareStatement(..., ResultSet.TYPE_SCROLL_INSENSITIVE)

Upvotes: 2

Views: 1342

Answers (1)

Reimeus
Reimeus

Reputation: 159844

This exception is typically caused by not calling Resultset#next prior to invoking one of the ResultSet's getter methods, appears to be getInt in this case.

Make sure to call

rs.next();

prior to using any of the getter methods.

Upvotes: 7

Related Questions