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

Ejava 3docx

Uploaded by

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

Ejava 3docx

Uploaded by

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

EXPERIMENT-3

Aim of the experiment:-


Implementation of commit and rollback with data base
operation.
Q-Write a java code to connect with Mysql or Oracle to
perform commit or rollback operation.
Code:
package CONNECTIVITY
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class rollbackCommit {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/EJAVA";
String user = "root";
String password = "biswa@2002";
Connection connection = null;
try {
[Link]("[Link]");
[Link]("Connecting to database...");
connection = [Link](url, user, password);
[Link]("Connected to the database!");
[Link](false);
Statement statement = [Link]();
String query = "SELECT * FROM SCHOOL";
ResultSet resultSet = [Link](query);
[Link]("Student Records:");
[Link]("ID\tName\tAge\tGrade");
while ([Link]()) {
int id = [Link]("id");
String name = [Link]("name");
int age = [Link]("age");
String grade = [Link]("grade");
[Link](id + "\t" + name + "\t" + age + "\t" + grade);
}
[Link]();
[Link]("Transaction committed successfully")
} catch (SQLException e) {
try {
if (connection != null) {
[Link]();
[Link]("Transaction rolled back due to an exception: " + [Link]());
}
} catch (SQLException ex) {
[Link]();
}
[Link]("Connection failed! Error message: " + [Link]());
} catch (Exception e) {
[Link]();
} finally {
try {
if (connection != null) {
[Link]();
[Link]("Connection closed.");
}
} catch (SQLException e) {
[Link]();
}
}
}
}

Output:

Name – Biswaranjan Sahoo


Regno-2101020707
Grp-3
Sem-5th

You might also like