0% found this document useful (0 votes)
16 views3 pages

Practical No 30

The document provides a Java program that demonstrates how to retrieve data from a MySQL database using the ResultSet interface. It includes various navigation methods such as first, last, absolute, and relative to access specific rows in the result set. The program connects to a 'Students' database, executes a SELECT query, and prints the retrieved data to the console.

Uploaded by

Sairaj Sawake
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Practical No 30

The document provides a Java program that demonstrates how to retrieve data from a MySQL database using the ResultSet interface. It includes various navigation methods such as first, last, absolute, and relative to access specific rows in the result set. The program connects to a 'Students' database, executes a SELECT query, and prints the retrieved data to the console.

Uploaded by

Sairaj Sawake
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Practical No.

30

3. Write program to retrieve data from table using ResultSet interface. (Use various methods
of navigation methods)

Code

package resultsetnavigationexample;

import [Link];

import [Link];

import [Link];

import [Link];

public class ResultSetNavigationExample {

public static void main(String[] args) {

String url = "jdbc:mysql://localhost:3306/Students";

String username = "root";

String password = "3367";

String selectQuery = "SELECT id, name, age, grade FROM students";

try {

Connection connection =
[Link]("jdbc:mysql://localhost:3306/Students", "root", "3367");

Statement statement = [Link](ResultSet.TYPE_SCROLL_INSENSITIVE,


ResultSet.CONCUR_READ_ONLY);

ResultSet resultSet = [Link](selectQuery);

[Link]("Navigating the ResultSet...");

if ([Link]()) {

[Link]("First row: " + [Link]("id") + ", " + [Link]("name"));

if ([Link]()) {

[Link]("Last row: " + [Link]("id") + ", " + [Link]("name"));


}

if ([Link](2)) {

[Link]("Second row: " + [Link]("id") + ", " +


[Link]("name"));

if ([Link](-1)) {

[Link]("Previous row relative to current: " + [Link]("id") + ", " +


[Link]("name"));

[Link]("\nIterating through all rows:");

[Link]();

while ([Link]()) {

[Link]([Link]("id") + ", " + [Link]("name") + ", " +


[Link]("age") + ", " + [Link]("grade"));

[Link]();

[Link]();

[Link]();

} catch (Exception e) {

[Link]();

}
Output:-

You might also like