- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelete.java
More file actions
Latest commit
29 lines (28 loc) · 1.04 KB
/
Copy pathDelete.java
File metadata and controls
29 lines (28 loc) · 1.04 KB
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
importjava.util.*;
importjava.sql.*;
classDelete {
publicstaticvoidmain(Stringargs[]) {
try {
inty, count = 0;
Scannerscan = newScanner(System.in);
Class.forName("com.mysql.jdbc.Driver");
Connectioncon = DriverManager.getConnection("jdbc:mysql://localhost:3306/company", "root", "root");
Statementstm = con.createStatement();
System.out.println("Enter the year:");
y = scan.nextInt();
Stringqry = "delete from employee where year<" + y;
count = stm.executeUpdate(qry);
if (count != 0) {
System.out.println("Data Deleted");
} else {
System.out.println("Not deleted");
}
con.close();
stm.close();
} catch (ClassNotFoundExceptione) {
System.out.println("Caught Exception:" + e);
} catch (SQLExceptione) {
System.out.println("Caught Exception:" + e);
}
}
}