-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatientRecords.java
138 lines (121 loc) · 6.1 KB
/
PatientRecords.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package hospital_management_system;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
public class PatientRecords extends javax.swing.JFrame {
private static Statement st;
private static ResultSet rs;
private static Connection con;
private static PreparedStatement stmt;
private static String tableName = "patienthistory";
DatabaseConnection dbcon = new DatabaseConnection();
public PatientRecords() {
initComponents();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
setLayout(null);
setLocationRelativeTo(null);
con = dbcon.returnConnectionObject();
st = dbcon.returnStatementObject();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(222, 222, 240));
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jTable1.setBackground(new java.awt.Color(222, 222, 240));
jTable1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"p_id", "d_id", "p_name", "p_gender", "p_age", "p_number", "p_address", "p_room", "p_admitdate", "p_dischargedate"
}
));
jScrollPane1.setViewportView(jTable1);
getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 718, 140));
jButton1.setBackground(new java.awt.Color(222, 222, 240));
jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jButton1.setText("Show Record");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 320, 170, 60));
jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Nasir Abbas Mangrio\\Documents\\NetBeansProjects\\Hospital_Management_System\\src\\Images\\hospital13.png")); // NOI18N
jLabel1.setText("jLabel1");
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 740, 440));
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
try {
String sql = "SELECT * FROM patienthistory";
st = con.createStatement();
rs = st.executeQuery(sql);
while (rs.next()) {
String p_id = String.valueOf(rs.getInt(1));
String d_id = String.valueOf(rs.getInt(2));
String p_name = rs.getString(3);
String p_gender = rs.getString(4);
String p_age = String.valueOf(rs.getInt(5));
String p_number = rs.getString(6);
String p_address = rs.getString(7);
String p_room = String.valueOf(rs.getInt(8));
String p_admitdate = rs.getString(9);
String p_dischargedate = rs.getString(10);
String obj[] = {p_id, d_id, p_name, p_gender, p_age, p_number, p_address, p_room, p_admitdate, p_dischargedate};
DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
dtm.addRow(obj);
}
} catch (SQLException ex) {
Logger.getLogger(PatientRecords.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_jButton1ActionPerformed
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(PatientRecords.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(PatientRecords.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(PatientRecords.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(PatientRecords.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PatientRecords().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
}