Java JDBC ResultSet Example
In this example, we are going to demonstrate how to use Java JDBC ResultSet in order to get and manipulate data from a database. ResultSet is essentially a table, which contains all the information that should be returned from a specific query, as well as some essential metadata.
You can also check this tutorial in the following video:
1. Why we use ResultSet interface
A ResultSet is a table of data representing a database result set, which is usually generated by executing a statement that queries the database. A ResultSet object maintains a cursor pointing to its current row of data, initially positioned before the first row. The ResultSet interface provides getter methods for retrieving column values from the current row. Values can be retrieved using the column name or the index number of the column. The usual syntax to get a ResultSet is as shown below:
Connection conn = DriverManager.getConnection(database specific URL);
Statement stmt = conn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
ResultSet rSet = stmt.executeQuery("query to execute passed as String");
while(rSet.next()){
// Fetch the results and perform operations
...
}
A ResultSet is obtained after executing a query. Download NOW!

