-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppointment.java
More file actions
150 lines (118 loc) · 4.94 KB
/
Appointment.java
File metadata and controls
150 lines (118 loc) · 4.94 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
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
139
140
141
142
143
144
145
146
147
148
149
150
package hospital_management;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
public class Appointment extends JFrame {
private JTable table = new JTable();
private JButton add = new JButton("ADD");
private JButton update = new JButton("Update");
private JButton close = new JButton("close");
private JLabel lab1 = new JLabel("CHANNEL ID");
private JTextField tf = new JTextField();
private JLabel lab = new JLabel("patientName");
private JTextField tf3 = new JTextField();
private JLabel labb = new JLabel("DoctorName");
private JTextField t4 = new JTextField();
private JLabel lab2 = new JLabel("Date ");
private JTextField tf1 = new JTextField();
private JPanel pan = new JPanel();
private JPanel pan1 = new JPanel();
public Appointment(String a,String b,String c){
tf.setText(a);
tf3.setText(b);
t4.setText(c);
add.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Connection con = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/java_project", "root", "1234");
stmt = con.createStatement();
String insert = "INSERT INTO appointment VALUES('" + tf.getText() + "','" + tf3.getText() + "','"
+ t4.getText() + "','" + tf1.getText() + "')";
stmt.executeUpdate(insert);
JOptionPane.showMessageDialog(null, "SAVED SUCCESSFULLY!");
tf.setText("");
tf3.setText("");
t4.setText("");
tf1.setText("");
} catch (ClassNotFoundException ex) {
Logger.getLogger(DoctorForm.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(DoctorForm.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
if (stmt != null) {
stmt.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger.getLogger(DoctorForm.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
update.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
String value1= tf.getText();;
String value2=tf3.getText();
String value3= t4.getText();
String value4= tf1.getText();
//String value6=jTextField6.getText();
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/java_project", "root", "1234");
String sql="update appointment set patientName='"+value2+"', doctorName='"+value3+"', date='"+value4+"' where channelNo='"+value1+"'";
PreparedStatement statement=con.prepareStatement(sql);
//Pst=conn.prepareStatement();
int rowsupdated= statement.executeUpdate(sql);
if(rowsupdated>0){
JOptionPane.showMessageDialog(null, "updated");
}else{
JOptionPane.showMessageDialog(null, "you didn't update any thing");}
} catch (SQLException ex) {
Logger.getLogger(Prescription.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Prescription.class.getName()).log(Level.SEVERE, null, ex);
}
tf.setText("");
tf3.setText("");
t4.setText("");
tf1.setText("");
}
});
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new View_Channel();
setVisible(false);
}
});
pan.setLayout(new GridLayout(4,2,5,6));
pan.add(lab1);
pan.add(tf);
pan.add(lab);
pan.add(tf3);
pan.add(labb);
pan.add(t4);
pan.add(lab2);
pan.add(tf1);
pan1.add(add);
pan1.add(update);
pan1.add(close);
add(pan,BorderLayout.CENTER);
add(pan1,BorderLayout.SOUTH);
setSize(400, 350);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}