This repository was archived by the owner on Jun 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_terminator.java
More file actions
71 lines (61 loc) · 2.28 KB
/
class_terminator.java
File metadata and controls
71 lines (61 loc) · 2.28 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class class_terminator {
// JDBC connection details
private static final String JDBC_URL = "jdbc:mysql://localhost:3306/examdb";
private static final String USERNAME = "root";
private static final String PASSWORD = "Chintutyagi@12";
private JFrame frame;
private JButton deleteButton;
private JLabel statusLabel;
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
try {
class_terminator window = new class_terminator();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
});
}
public class_terminator() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setTitle("Delete Table Content");
frame.setBounds(100, 100, 350, 150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
deleteButton = new JButton("Delete");
deleteButton.setBounds(120, 40, 100, 25);
frame.getContentPane().add(deleteButton);
statusLabel = new JLabel("");
statusLabel.setBounds(20, 80, 300, 15);
statusLabel.setForeground(Color.GREEN);
frame.getContentPane().add(statusLabel);
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deleteTableContent();
}
});
}
private void deleteTableContent() {
try (Connection conn = DriverManager.getConnection(JDBC_URL, USERNAME, PASSWORD)) {
String deleteQuery = "DELETE FROM classes";
try (PreparedStatement stmt = conn.prepareStatement(deleteQuery)) {
int rowsAffected = stmt.executeUpdate();
if (rowsAffected > 0) {
statusLabel.setText("Table content deleted successfully.");
} else {
statusLabel.setText("No records to delete.");
}
}
} catch (SQLException ex) {
ex.printStackTrace();
statusLabel.setText("Error connecting to the database.");
}
}
}