Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Department of Information Technology

Semester S.E. Semester III – INFT


Subject Advance Java Lab
Laboratory Prof. Neha Kudu
Teacher:
Laboratory -

Student Name Ganesh Waghmare


Roll Number 22101A0014
Grade and
Subject Teacher’s
Signature

Experiment 1
Number
Problem Write a program to perform following operations on database table
Statement
[Table: Employee, Fields: Id,Name,Address]
1. Insert new record in database table.
2. Delete any record from database table.
3. Update particular record.
4. Display contents of database table.
Resources / Hardware: Desktop/Laptop Software:
Apparatus
Required
Code: import java.sql.*;
public class Main
{
public static void main(String[] args)
{
try
{
Class.forName("com.sql.jdbc.Driver");
Connection c=
DriverManager.getConnection("jdbc:mysql://localhost/INFT","root","
arya@02");
Statement s= c.createStatement();
s.execute("insert into employee values(4,'GGG','HHH')");
System.out.println("Record Inserted...");
s.execute("delete from employee where ID=2");
System.out.println("Record Deleted...");
s.executeUpdate("update employee set Name='SSS' where
Address='FFF'");
System.out.println("Record Updated...");
ResultSet rs= s.executeQuery("select * from employee");
while(rs.next())
{
System.out.println(rs.getInt(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
}
System.out.println("Record Displayed...");
rs.close();
s.close();
c.close();
}
catch(Exception e)
{
System.out.println("Exception Occurs...");

}
}
}
Output:

You might also like