-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeleteData.java
44 lines (29 loc) · 1021 Bytes
/
DeleteData.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
36
37
38
39
40
41
42
43
44
package jdbcDemo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class DeleteData {
public static void main(String[] args) throws SQLException {
Connection connection=null;
Statement statement=null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connection =DriverManager.getConnection("jdbc:mysql://localhost:3307/school_information_system","root","");
statement=connection.createStatement();
String sql="DELETE FROM employee WHERE id=2";
int isDeleted=statement.executeUpdate(sql);
if(isDeleted==1) {
System.out.println("Record deleted Successfully");
}
}catch(ClassNotFoundException ex){
System.out.println("Driver class could not be loaded");
}catch(SQLException sqlEx) {
System.out.println(" exception occured when carrying an SQL operation"+sqlEx.getMessage());
}finally {
if(connection!=null) {
connection.close();
}
}
}
}