What is ResultSet in jdbc?

java.sql.ResultSet is a java object that is used for database connectivity to hold the data returned by a select query.

When we run a select query it returns us the data in a table format with each row representing one logical group of data with a number of columns.

The result set would contain this table of data and each row can be accessed one by one. we can use the resultset.get() methods to get the data from it.

Example:

ResultSet rs = prepStmt.executeQuery(); //Assumption - prepStmt is a valid preparedstatement with a valid query

while(rs.next()){
System.out.println("Name: " + rs.getString(1));
System.out.println("Age: " + rs.getInt(2));
}

the rs.getString() method would return us a String data type and similarly the rs.getInt() would return us an integer data type

the numbers 1 & 2 represent the column position in the result set where our data is present.
java.sql.ResultSet is a java object that is used for database connectivity to hold the data returned by a select query.

When we run a select query it returns us the data in a table format with each row representing one logical group of data with a number of columns.

The result set would contain this table of data and each row can be accessed one by one. we can use the resultset.get() methods to get the data from it.

Example:

ResultSet rs = prepStmt.executeQuery(); //Assumption - prepStmt is a valid preparedstatement with a valid query

while(rs.next()){
System.out.println("Name: " + rs.getString(1));
System.out.println("Age: " + rs.getInt(2));
}

the rs.getString() method would return us a String data type and similarly the rs.getInt() would return us an integer data type

the numbers 1 & 2 represent the column position in the result set where our data is present.