I want to get the size of the ResultSet inside the while loop.
Tried the code below, and I got the results that I want. But it seems to be messing up with result.next() and the while loop only loops once if I do this.
What’s the proper way of doing this?
result.first();
while (result.next()){
System.out.println(result.getString(2));
System.out.println("A. " + result.getString(5) + "\n" + "B. " + result.getString(6) + "\n" + "C. " + result.getString(7) + "\n" + "D. " + result.getString(8));
System.out.println("Answer: ");
answer = inputquiz.next();
result.last();
if (answer.equals(result.getString(10))) {
score++;
System.out.println(score + "/" + result.getRow());
} else {
System.out.println(score + "/" + result.getRow());
}
}
Map it to a
List<Entity>. Since your code is far from self-documenting (you’re using indexes instead of column names), I can’t give a well suited example. So I’ll take aPersonas example.First create a javabean class representing whatever a single row contains.
(a bit decent IDE like Eclipse can autogenerate them)
Then let JDBC do the following job.
Then you can just do
And then to substitute your code example
See also: