-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB.java
More file actions
69 lines (61 loc) · 2.71 KB
/
DB.java
File metadata and controls
69 lines (61 loc) · 2.71 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
package SMS;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.sql.*;
public class DB {
public static final String DB_URL ="jdbc:mysql://localhost:3306/sms";
public static final String USER = "root";
public static final String PASSWORD = "admin";
public static Connection getConnection() throws SQLException{
return DriverManager.getConnection(DB_URL, USER, PASSWORD);
}
public static void loadTableData1(DefaultTableModel tableModel1){
try{
Connection connection1 = getConnection();
Statement statement1 = connection1.createStatement();
ResultSet resultSet1 = statement1.executeQuery("SELECT * FROM student");
tableModel1.setRowCount(0);
while (resultSet1.next()){
Object[] rowData = {
resultSet1.getString("ID"),
resultSet1.getString("Student_Name"),
resultSet1.getString("Father_Name"),
resultSet1.getString("Mother_Name"),
resultSet1.getString("DOB"),
resultSet1.getString("Class"),
resultSet1.getString("Phone_Number")
};
tableModel1.addRow(rowData);
}
resultSet1.close();
statement1.close();
connection1.close();
}catch (SQLException ex){
JOptionPane.showMessageDialog(null,"Error:"+ex.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
}
}
public static void loadTableData2(DefaultTableModel tableModel2, String id){
try {
Connection connection2 = getConnection();
PreparedStatement statement2 = connection2.prepareStatement("SELECT * FROM fee WHERE ID=?");
statement2.setString(1,id);
ResultSet resultSet2 = statement2.executeQuery();
tableModel2.setRowCount(0);
while (resultSet2.next()){
Object[] rowData = {
resultSet2.getString("Fee_Month"),
resultSet2.getString("Submission_Date"),
resultSet2.getString("Tution_Fee"),
resultSet2.getString("Amount_Paid"),
resultSet2.getString("Pending")
};
tableModel2.addRow(rowData);
}
resultSet2.close();
statement2.close();
connection2.close();
}catch (SQLException ex){
JOptionPane.showMessageDialog(null,"Error:"+ex.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
}
}
}