Prac 18 Final
Prac 18 Final
Title:= Write a program to insert and retrive the data from the database using JDBC
Rollno:=27 Batch:=B DOP:=15/10/24
SOURCE CODE:=
import java.sql.*;
public class Connectivity
{
Connection con;
Statement stmt;
Connectivity()
{
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver Loaded");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","");
System.out.println("Connection Established");
stmt=con.createStatement();
stmt.executeUpdate("insert into studentinfo values(4,'Dhanu','WIN','123478456')");
System.out.println("1 row Inserted");
stmt.executeUpdate("delete from studentinfo where rollno=1");
System.out.println("1 row is deleted");
stmt.executeUpdate("update studentinfo set sname='Sam' where rollno=2");
System.out.println("Row is updated");
while(rs.next())
{
System.out.println("Student rollno:"+rs.getInt(1));
System.out.println("Student Name:"+rs.getString(2));
System.out.println("Student div:"+rs.getString(3));
System.out.println("Student mob:"+rs.getString(4));
}
} catch (ClassNotFoundException | SQLException ex)
{
}
}
public static void main(String[] args)
{
Connectivity n=new Connectivity();
}
}
OUTPUT:
run:
Driver Loaded
Connection Established
1 row Inserted
1 row is deleted
Row is updated
Student rollno:1
Student Name:payal
Student div:WIN
Student mob:869878456
Student rollno:3
Student Name:Sam
Student div:mac
Student mob:7486974567
Student rollno:4
Student Name:Dhanu
Student div:WIN
Student mob:123478456
Student rollno:5
Student Name:Rishabh
Student div:win
Student mob:867573962
Student rollno:6
Student Name:payal
Student div:WIN
Student mob:869878456