-2

I get an error trying to execute this code.

My requirement is to use getInt() to convert a string in to DB.

for (int i = 1; i <= 7; i++) {
    int t = rs.getInt(i);

    temp = Integer.toString(t);
    if (temp.length() == 1) temp="00"+temp;
    else if (temp.length() == 2) temp="0"+temp;
    else temp=temp;
    output=output+temp;
       ...

Error

John Hascall
  • 9,176
  • 6
  • 48
  • 72

2 Answers2

0

It seems like your result set has fewer than seven rows, so you run out of them in the for loop. It's a good idea to check rs.hasNext() to see if there are any more rows to process.

Ken Clubok
  • 1,238
  • 6
  • 11
0

You didn't show the relevant piece of code (but it's visible in the screenshot), which is the while loop preceding the for loop you included:

while (rs.next()) {
    blah blah blah
}

That loop reads all rows from the SQL select statement, leaving the ResultSet fully consumes (aka exhausted).

When you then rs.getInt(i) after rs.next() returned false, you are told, "sorry, no can do, you already used all the data", aka SQLException: Exhausted Resultset.

Andreas
  • 154,647
  • 11
  • 152
  • 247