O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieving Results of a Query

ResultSet rs = stmt.executeQuery(
											"SELECT name, password FROM users
											where name='tim'");
											while (rs.next( )) {
											String name = rs.getString(1);
											String password = rs.getString(2);
											}

A JDBC query returns a ResultSet object. A ResultSet represents a table of data containing the results of a database query. We can step through the ResultSet contents to get the results of the executed query. The ResultSet maintains a cursor that points to the current row of data. The ResultSet object has a next() method, which moves the cursor to the next row. The next() method will return false when there are no more rows in the ResultSet object. This makes it easy to use a while loop for stepping through all the rows contained within a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required