-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDelete.java
34 lines (32 loc) · 1.3 KB
/
Delete.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
import java.sql.*;
public class Delete {
public static void main(String args[]) throws ClassNotFoundException {
String url = "jdbc:mysql://localhost:3306/mydatabase";
String username = "root";
String password = "System@321sql";
String query = "DELETE FROM employees where id = 6;";
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver loaded successfully");
} catch(ClassNotFoundException e) {
System.out.println(e.getMessage());
}
try {
Connection con = DriverManager.getConnection(url, username, password);
System.out.println("connection established successfully");
Statement st = con.createStatement();
int rowsaffected = st.executeUpdate(query);
if(rowsaffected>0) {
System.out.println("Deletion Successfully"+rowsaffected+ "row(s) affected.");
}else {
System.out.println("Deletion Failed..");
}
st.close();
con.close();
System.out.println();
System.out.println("connection closed successfully!!!");
} catch(SQLException e) {
System.out.println(e.getMessage());
}
}
}