0% found this document useful (0 votes)
3 views2 pages

Prac 18 Final

practical 18

Uploaded by

kaverinagare39
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)
3 views2 pages

Prac 18 Final

practical 18

Uploaded by

kaverinagare39
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
You are on page 1/ 2

Practical No:=18

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");

ResultSet rs=stmt.executeQuery("select * from studentinfo");

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

You might also like