-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateStudent.java
320 lines (270 loc) · 13.4 KB
/
UpdateStudent.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
package UniBuddy;
import java.awt.*;
import java.awt.event.*;
import java.sql.ResultSet;
import java.sql.*;
import javax.swing.*;
import com.toedter.calendar.JDateChooser;
//import java.util.*;
public class UpdateStudent extends JFrame implements ActionListener{
/*Random rand = new Random();
long first6 = Math.abs((rand.nextLong()%900000L) + 100000L);
JLabel studentRollNumberLabel;*/
JTextField studentAddressTextField, studentPhoneTextField, studentTenthPercentageTextField, studentTwelthPercentageTextField;
JTextField studentEmaTextField, studentGenderTextField, studentAadharNumberTextField;
JTextField studentCourseBox, studentBranchBox;
JLabel studentRollNumber;
JButton studentUpdate, studentCancel;
Choice studentRollNumberC;
UpdateStudent(){
setSize(900, 700);
setLocation(350, 50);
setLayout(null);
//Update student details heading
JLabel headingStudentAdd = new JLabel("Update Student Details");
headingStudentAdd.setBounds(310, 30, 500, 50);
headingStudentAdd.setFont(new Font("Sarif", Font.BOLD, 30)); /*awt*/
add(headingStudentAdd);
JLabel sRollNumber = new JLabel("Select Student Roll Number");
sRollNumber.setFont(new Font("Sarif", Font.BOLD, 20));
sRollNumber.setBounds(50,100,300,20);
add(sRollNumber);
studentRollNumberC = new Choice();
studentRollNumberC.setFont(new Font("Sarif", Font.BOLD, 15));
studentRollNumberC.setBounds(350,100,200,20);
add(studentRollNumberC);
try {
Conn c = new Conn();
ResultSet rs = c.s.executeQuery("select * from studentdetails");
while(rs.next()){
studentRollNumberC.add(rs.getString("rollnumber"));
}
}catch(Exception e){
e.printStackTrace();
}
//New Student
JLabel studentNameLabel = new JLabel("Name : ");
studentNameLabel.setBounds(50, 150, 100, 30);
studentNameLabel.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentNameLabel);
JLabel studentNameTextField = new JLabel();
studentNameTextField.setFont(new Font("Sarif", Font.BOLD, 15));
studentNameTextField.setBounds(200, 150, 150, 30);
add(studentNameTextField);
//Father Name
JLabel studentFatherNameLabel = new JLabel("Father's Name : ");
studentFatherNameLabel.setBounds(400, 150, 200, 30);
studentFatherNameLabel.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentFatherNameLabel);
JLabel studentFatherNameTextField = new JLabel();
studentFatherNameTextField.setFont(new Font("Sarif", Font.BOLD, 15));
studentFatherNameTextField.setBounds(600, 150, 150, 30);
add(studentFatherNameTextField);
//Mother Name
JLabel studentMotherNameLabel = new JLabel("Mother's Name : ");
studentMotherNameLabel.setBounds(400, 200, 200, 30);
studentMotherNameLabel.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentMotherNameLabel);
JLabel studentMotherNameTextField = new JLabel();
studentMotherNameTextField.setFont(new Font("Sarif", Font.BOLD, 15));
studentMotherNameTextField.setBounds(600, 200, 150, 30);
add(studentMotherNameTextField);
//Student Roll Number
studentRollNumber = new JLabel("Roll Number : ");
studentRollNumber.setBounds(50, 200, 200, 30);
studentRollNumber.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentRollNumber);
JLabel studentRollNumberTextField = new JLabel();
studentRollNumberTextField.setFont(new Font("Sarif", Font.BOLD, 15));
studentRollNumberTextField.setBounds(200, 200, 150, 30);
add(studentRollNumberTextField);
/*
studentRollNumberLabel = new JLabel("RA2211"+first6);
studentRollNumberLabel.setBounds(200, 200, 200, 30);
studentRollNumberLabel.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentRollNumberLabel);
*/
//Date of Birth
JLabel studentDOB = new JLabel("Date of Birth : ");
studentDOB.setBounds(50, 250, 200, 30);
studentDOB.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentDOB);
JLabel JDate = new JLabel();
JDate.setFont(new Font("Sarif", Font.BOLD, 15));
JDate.setBounds(200, 250, 150, 30);
add(JDate);
//Student Gender
JLabel studentGender = new JLabel("Gender : ");
studentGender.setBounds(50, 300, 200, 30);
studentGender.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentGender);
JLabel studentGenderBox = new JLabel();
studentGenderBox.setFont(new Font("Sarif", Font.BOLD, 15));
studentGenderBox.setBounds(200, 300, 150, 30);
add(studentGenderBox);
/*
studentGenderTextField = new JTextField();
studentGenderTextField= new JTextField();
studentGenderTextField.setBounds(200, 300, 150, 30);
add(studentGenderTextField);
*/
//Student Address
JLabel studentAddress = new JLabel("Current Address : ");
studentAddress.setBounds(400, 300, 200, 30);
studentAddress.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentAddress);
studentAddressTextField = new JTextField();
studentAddressTextField.setBounds(600, 300, 150, 30);
add(studentAddressTextField);
//Student Phone
JLabel studentPhone = new JLabel("Phone Number : ");
studentPhone.setBounds(400, 250, 200, 30);
studentPhone.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentPhone);
studentPhoneTextField= new JTextField();
studentPhoneTextField.setBounds(600, 250, 150, 30);
add(studentPhoneTextField);
//Student Aadhar Number
JLabel studentAadharNumber = new JLabel("Aadhar Number : ");
studentAadharNumber.setBounds(50, 350, 200, 30);
studentAadharNumber.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentAadharNumber);
JLabel studentAadharNumberTextField= new JLabel();
studentAadharNumberTextField.setFont(new Font("Sarif", Font.BOLD, 15));
studentAadharNumberTextField.setBounds(230, 350, 120, 30);
add(studentAadharNumberTextField);
//Student Tenth Percentage
JLabel studentTenthPercentage = new JLabel("10th Marks(%) : ");
studentTenthPercentage.setBounds(50, 400, 200, 30);
studentTenthPercentage.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentTenthPercentage);
JLabel studentTenthPercentageTextField = new JLabel();
studentTenthPercentageTextField.setFont(new Font("Sarif", Font.BOLD, 15));
studentTenthPercentageTextField.setBounds(220, 400, 130, 30);
add(studentTenthPercentageTextField);
//Student Twelth Percentage
JLabel studentTwelthPercentage = new JLabel("12th Marks(%) : ");
studentTwelthPercentage.setBounds(400, 400, 200, 30);
studentTwelthPercentage.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentTwelthPercentage);
JLabel studentTwelthPercentageTextField = new JLabel();
studentTwelthPercentageTextField.setFont(new Font("Sarif", Font.BOLD, 15));
studentTwelthPercentageTextField.setBounds(600, 400, 150, 30);
add(studentTwelthPercentageTextField);
//Student EMail Address
JLabel studentEmail = new JLabel("E-Mail Address : ");
studentEmail.setBounds(400, 350, 200, 30);
studentEmail.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentEmail);
studentEmaTextField = new JTextField();
studentEmaTextField.setBounds(600, 350, 150, 30);
add(studentEmaTextField);
//Student Course
JLabel studentCourse = new JLabel("Course : ");
studentCourse.setBounds(50, 450, 200, 30);
studentCourse.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentCourse);
JTextField studentCourseBox = new JTextField();
studentCourseBox.setBounds(200, 450, 150, 30);
add(studentCourseBox);
//Student Branch
JLabel studentBranch = new JLabel("Branch : ");
studentBranch.setBounds(400, 450, 200, 30);
studentBranch.setFont(new Font("Sarif", Font.BOLD, 20));
add(studentBranch);
JTextField studentBranchBox = new JTextField();
studentBranchBox.setBounds(600, 450, 150, 30);
add(studentBranchBox);
/*try{
Conn c = new Conn();
String query = "select * from studentdetails where rollnumber='"+studentRollNumberC.getSelectedItem()+"'";
ResultSet rs = c.s.executeQuery(query);
while(rs.next()){
studentNameTextField.setText(rs.getString("studentname"));
studentFatherNameTextField.setText(rs.getString("fathername"));
studentMotherNameTextField.setText(rs.getString("mothername"));
studentAadharNumberTextField.setText(rs.getString("aadhar"));
studentGenderBox.setText(rs.getString("gender"));
JDate.setText(rs.getString("dateofbirth"));
studentRollNumberTextField.setText(rs.getString("rollnumber"));
studentTenthPercentageTextField.setText(rs.getString("tenthmarks"));
studentTwelthPercentageTextField.setText(rs.getString("twelfthmarks"));
studentPhoneTextField.setText(rs.getString("phonenumber"));
studentEmaTextField.setText(rs.getString("email"));
studentAddressTextField.setText(rs.getString("address"));
studentCourseBox.setText(rs.getString("course"));
studentBranchBox.setText(rs.getString("branch"));
}
}catch(Exception e){
e.printStackTrace();
}*/
studentRollNumberC.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ie){
try{
Conn c = new Conn();
String query = "select * from studentdetails where rollnumber='"+studentRollNumberC.getSelectedItem()+"'";
ResultSet rs = c.s.executeQuery(query);
while(rs.next()){
studentNameTextField.setText(rs.getString("studentname"));
studentFatherNameTextField.setText(rs.getString("fathername"));
studentMotherNameTextField.setText(rs.getString("mothername"));
studentAadharNumberTextField.setText(rs.getString("aadhar"));
studentGenderBox.setText(rs.getString("gender"));
JDate.setText(rs.getString("dateofbirth"));
studentRollNumberTextField.setText(rs.getString("rollnumber"));
studentTenthPercentageTextField.setText(rs.getString("tenthmarks"));
studentTwelthPercentageTextField.setText(rs.getString("twelfthmarks"));
studentPhoneTextField.setText(rs.getString("phonenumber"));
studentEmaTextField.setText(rs.getString("email"));
studentAddressTextField.setText(rs.getString("address"));
studentCourseBox.setText(rs.getString("course"));
studentBranchBox.setText(rs.getString("branch"));
}
}catch(Exception e){
e.printStackTrace();
}
}
});
studentUpdate = new JButton("Update");
studentUpdate.setBounds(200, 550, 150, 40);
studentUpdate.setBackground(Color.black);
studentUpdate.setForeground(Color.black);
studentUpdate.setFont(new Font("Serif", Font.BOLD, 17));
studentUpdate.addActionListener(this);
add(studentUpdate);
studentCancel = new JButton("Cancel");
studentCancel.setBounds(500, 550, 150, 40);
studentCancel.setBackground(Color.black);
studentCancel.setForeground(Color.black);
studentCancel.setFont(new Font("Serif", Font.BOLD, 17));
studentCancel.addActionListener(this);
add(studentCancel);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==studentUpdate){
String sRollNumber = studentRollNumber.getText();
String sPhone = studentPhoneTextField.getText();
String sEmail = studentEmaTextField.getText();
String sAddress = studentAddressTextField.getText();
String sCourse = studentCourseBox.getText();
String sBranch = studentBranchBox.getText();
try {
String query = "update studentdetails set address='"+sAddress+"' ,phonenumber='"+sPhone+"', email='"+sEmail+"', course='"+sCourse+"', branch='"+sBranch+"' where rollnumber='"+sRollNumber+"'";
Conn c = new Conn();
c.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Student details UPDATED successfully");
setVisible(false);
} catch (Exception a) {
a.printStackTrace();
}
}
else{
JOptionPane.showMessageDialog(null, "Student details were NOT UPDATED");
setVisible(false);
}
}
public static void main(String[] args) {
new UpdateStudent();
}
}