A ResultSet is java object that store the result given by database after executing the query.We also say that it is hold the rows that satisfy the sql query condition.
Suppose we write a query that fetch the record of students whose city name is London.
ResultSet rs = stmt.executeQuery("SELECT * FROM students_data where city_name=‘London’”);
Here ResultSet hold the row where city name is London.
import java.sql.*;
class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection( “jdbc:mysql://localhost:3306/students","root","Students@123");
PreparedStatement stmt=con.prepareStatement("SELECT * FROM students_data where city_name=‘London’");
ResultSet rs=stmt.executeQuery();
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}
catch(Exception e){ System.out.println(e);}
}
}