Join David Gassner for an in-depth discussion in this video Looping through result sets, part of Java Database Integration with JDBC.
- View Offline
When data is returned from the database server, it's encapsulated within the ResultSet object.…The ResultSet has a cursor and in-memory pointer that goes from row to row.…When the ResultSet is first returned, the starting cursor position is before the first row of…data, that is, it's not pointing to any data at first.…You have to explicitly move the cursor to the data in order to read it.…The cursor can either be before the first row of data, on a row of data, or after the last row of data.…
All ResultSets give you the ability to move the cursor forward, so the cursor starts before…the first row, and the first thing you need to do is move it to the first row.…If you're working with a scrollable ResultSet, you can explicitly move to a particular row,…but if you're working with what's called a forward only ResultSet, that is a result set…where the cursor can only move forward, then you move the cursor one row at a time by calling…a method called Next. The Next method returns a Boolean value.…When you call it, if it succeeds in moving the cursor to a row that has data, it returns…
Author David Gassner explains how to choose a JDBC driver and connect to one or more databases. He also provides detailed instructions on reading, selecting, and updating data; calling stored procedures; managing data via JavaBean classes or with prepared statements; and working with metadata.
- Importing a MySQL database
- Connecting to databases
- Handling JDBC exceptions
- Looping through result sets
- Limiting the number of fetched rows
- Filtering data with prepared statements
- Calling stored procedures
- Inserting, updating, and deleting rows with prepared statements
- Using a persistent database connection
- Committing and rolling back transactions