2

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)

nlowe
  • 999
  • 4
  • 11
  • 26

1 Answers1

7

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.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • 1
    Thank you! Wasn't exactly this but that helped solved my problem! I wasn't re-winding the result set after I counted the rows with a utility function. Thanks again! – nlowe May 27 '13 at 00:55