-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSalesReport.java
More file actions
78 lines (66 loc) · 2.51 KB
/
SalesReport.java
File metadata and controls
78 lines (66 loc) · 2.51 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
72
73
74
75
76
77
78
package hospital_management;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.table.DefaultTableModel;
public class SalesReport extends JFrame {
private JButton close = new JButton("Close");
private JButton logout = new JButton("LogOut");
private JTable table = new JTable();
private JPanel pan = new JPanel();
SalesReport() {
table1();
JScrollPane scrollPane = new JScrollPane(table); // Wrap the JTable in a JScrollPane
pan.setLayout(new BorderLayout());
pan.add(scrollPane, BorderLayout.CENTER); // Add the JScrollPane to the JPanel
JPanel buttonPanel = new JPanel();
buttonPanel.add(close);
buttonPanel.add(logout);
pan.add(buttonPanel, BorderLayout.PAGE_END);
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Pharmacist();
}
});
add(pan);
setTitle("Sales Report");
setSize(300, 200);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void table1() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/java_project", "root", "1234");
PreparedStatement pst = con.prepareStatement("SELECT * FROM item");
ResultSet rs = pst.executeQuery();
DefaultTableModel model = new DefaultTableModel();
model.addColumn("presid");
model.addColumn("channel_id");
model.addColumn("doctor_name");
model.addColumn("des_type");
model.addColumn("description");
while (rs.next()) {
Object[] rowData = new Object[5];
rowData[0] = rs.getString("presid");
rowData[1] = rs.getString("channel_id");
rowData[2] = rs.getString("doctor_name");
rowData[3] = rs.getString("des_type");
rowData[4] = rs.getString("description");
model.addRow(rowData);
}
table.setModel(model);
rs.close();
pst.close();
con.close();
} catch (ClassNotFoundException | SQLException ex) {
ex.printStackTrace();
}
}
}