0

The VoltDB package has an example setup called 'voter.' I'm running that on the server and trying to work with it in Java. I am able to create a ResultSet with Statement.executeQuery and "SELECT * FROM voter;" it has the correct columns (PHONE_NUMBER, STATE, and CONTESTANT_NUMBER), but no rows. When I try to get anything from the resultSet, I get the following error:

Exception in thread "main"
java.sql.SQLException: s1000
Caused by: java.lang.RuntimeException: VoltTableRow.advanceRow() must be called to advance to the first row before any access.

I don't see how I'm supposed to use VoltTableRow.advanceRow() in the code, like it says there. I'm also getting the same problem (correct columns, no rows) when I use the provided VoltDB studio setup (which doesn't rely on my Java code at all), with select * from votes giving me three columns and no rows, so I'm thinking it's probably not just a mistake in the Java code, but the relevant code is included below:

Statement jdbcStmt;
String jdbcSelect = "SELECT * FROM voter;";
ResultSet rs = jdbcStmt.executeQuery(jdbcSelect);

(The portions of the code not directly related to the creation of this ResultSet are omitted.)

Lateral
  • 41
  • 6

2 Answers2

0

You should first call ResultSet#next before attempting to retrieve any data:

ResultSet rs = jdbcStmt.executeQuery(jdbcSelect);
if (rs.next()) {
    //just an example
    String foo = rs.getString(1);
}
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • Tried that. Doesn't work. It doesn't break, but it still pulls zero records. – Lateral Jul 15 '14 at 17:51
  • @user3779281 then you have no records to retrieve. Make sure you're pointing to the right database, schema and table. – Luiggi Mendoza Jul 15 '14 at 17:52
  • Well, yeah, I think that's the problem. I'm definitely pointing to the correct table, but the table doesn't seem to hold any data. – Lateral Jul 15 '14 at 17:53
  • Doesn't work that way. The table is supposed to be autogenerated. I don't have a way to put data into it directly. – Lateral Jul 15 '14 at 17:55
  • @user3779281 then why do you expect to retrieve any data if there's none in the table? You solved the main problem in your question which is to avoid the exception. Your current problem is up to you. – Luiggi Mendoza Jul 15 '14 at 18:57
  • The voter example includes a client application that autogenerates data that is inserted into the "votes" table by calling the "Vote" procedure. You can run the client using the command "run.sh client". The README has more detailed instructions. – BenjaminBallard Jul 16 '14 at 16:55
  • @BenBallard probably you wanted to send the message to OP. Please use `@` to sent a response to a specific user in comments. – Luiggi Mendoza Jul 16 '14 at 17:19
0

Never mind, the client application broke at some point between when I set it up and when I needed its data. Running it again fixed the problem.

Lateral
  • 41
  • 6