-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.java
35 lines (23 loc) · 1.01 KB
/
remove.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.sql.*; //step 1 import package
public class remove {
public static void main(String[] args) throws Exception {
//Class.forName("com.mysql.jdbc.Driver"); //step 2 load and register driver class
String url="jdbc:mysql://localhost:3306/SI";
Connection conn=DriverManager.getConnection(url,"root","Vidya@2001"); //step 3 establish connection
Statement s=conn.createStatement(); // step 4 create statement object
String sql="delete from student where id=6";
int r=s.executeUpdate(sql); //perform operation, r has the value of the number of rows affected
ResultSet rs=s.executeQuery("select * from student");
while(rs.next()){
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
}
if(r>=1){
System.out.println("Data deletion Successful");
}
else{
System.out.println("Data deletion Failed");
}
s.close(); //close statement object
conn.close(); //close connection object
}
}