-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateTeacherDetails.java
266 lines (236 loc) · 9.76 KB
/
UpdateTeacherDetails.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
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import com.toedter.calendar.JDateChooser;
import java.text.DateFormat;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.JOptionPane;
class UpdateTeacherDetails extends JFrame implements ActionListener
{
JLabel title,nameLabel,empIDLabel, addressLabel,emailLabel,classXIILabel,departmentLabel,fatherNameLabel, dOBLabel, phoneLabel,classXLabel,aadharLabel,educationLabel;
JTextField nameField,addressField,emailField, classXIIField, courseField, fatherField, phoneField,classXField,aadharField;
JButton submitBtn, cancleBtn;
JComboBox departmentComboBox,educationComboBox,employeeIDField;
String[] educationList, departmentList,empIDList;
JDateChooser DOB;
ResultSet rs;
Connection c;
Statement st;
UpdateTeacherDetails()
{
this.setLayout(null);
title=new JLabel("Update Teacher Details");
title.setBounds(350, 40, 450, 50);
title.setFont(new Font("serif", Font.BOLD, 35));
this.add(title);
nameLabel=new JLabel("Name");
nameLabel.setBounds(50, 140, 250, 20);
nameLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(nameLabel);
nameField=new JTextField();
nameField.setBounds(250,140,200,30);
this.add(nameField);
empIDLabel=new JLabel("Emp ID");
empIDLabel.setBounds(50, 200, 250, 20);
empIDLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(empIDLabel);
employeeIDField=new JComboBox(getEmpIDFromDB());
employeeIDField.setBounds(250,200,200,30);
employeeIDField.setFont(new Font("serif", Font.PLAIN, 20));
this.add(employeeIDField);
addressLabel=new JLabel("Address");
addressLabel.setBounds(50, 260, 250, 20);
addressLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(addressLabel);
addressField=new JTextField();
addressField.setBounds(250,260,200,30);
this.add(addressField);
emailLabel=new JLabel("Email");
emailLabel.setBounds(50, 320, 250, 20);
emailLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(emailLabel);
emailField=new JTextField();
emailField.setBounds(250,320,200,30);
this.add(emailField);
classXIILabel=new JLabel("Class XII marks(%)");
classXIILabel.setBounds(50, 380, 250, 20);
classXIILabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(classXIILabel);
classXIIField=new JTextField();
classXIIField.setBounds(250,380,200,30);
this.add(classXIIField);
departmentLabel=new JLabel("Department");
departmentLabel.setBounds(50, 440, 250, 20);
departmentLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(departmentLabel);
departmentList=getDepartmentList();
departmentComboBox=new JComboBox(departmentList);
departmentComboBox.setBounds(250,440,200,30);
this.add(departmentComboBox);
fatherNameLabel=new JLabel("Father's Name");
fatherNameLabel.setBounds(550, 140, 250, 20);
fatherNameLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(fatherNameLabel);
fatherField=new JTextField();
fatherField.setBounds(720,140,200,30);
this.add(fatherField);
dOBLabel=new JLabel("DOB");
dOBLabel.setBounds(550, 200, 250, 20);
dOBLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(dOBLabel);
DOB=new JDateChooser();
DOB.setBounds(720,200,200,30);
this.add(DOB);
phoneLabel=new JLabel("Phone");
phoneLabel.setBounds(550, 260, 250, 20);
phoneLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(phoneLabel);
phoneField=new JTextField();
phoneField.setBounds(720,260,200,30);
this.add(phoneField);
classXLabel=new JLabel("Class X marks(%)");
classXLabel.setBounds(550, 320, 250, 20);
classXLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(classXLabel);
classXField=new JTextField();
classXField.setBounds(720,320,200,30);
this.add(classXField);
aadharLabel=new JLabel("Aadhar");
aadharLabel.setBounds(550, 380, 250, 20);
aadharLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(aadharLabel);
aadharField=new JTextField();
aadharField.setBounds(720,380,200,30);
this.add(aadharField);
educationLabel=new JLabel("Branch");
educationLabel.setBounds(550, 440, 250, 20);
educationLabel.setFont(new Font("serif", Font.PLAIN, 20));
this.add(educationLabel);
educationList=getEducationList();
educationComboBox=new JComboBox(educationList);
educationComboBox.setBounds(720,440,200,30);
this.add(educationComboBox);
submitBtn=new JButton("Update");
submitBtn.setBackground(Color.BLACK);
submitBtn.setForeground(Color.WHITE);
submitBtn.setBounds(250,550,150,40);
submitBtn.setFont(new Font("serif", Font.PLAIN, 25));
submitBtn.addActionListener(this);
this.add(submitBtn);
cancleBtn=new JButton("Cancel");
cancleBtn.setBackground(Color.BLACK);
cancleBtn.setForeground(Color.WHITE);
cancleBtn.setBounds(580,550,150,40);
cancleBtn.setFont(new Font("serif", Font.PLAIN, 25));
cancleBtn.addActionListener(this);
this.add(cancleBtn);
this.setSize(1000,750);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public String[] getEducationList()
{
String[] a={"B.Tech","B.Com","B.Sc"};
return a;
}
public String[] getDepartmentList()
{
String[] a={"Computer Science","Mechanical","Civil","IT","Electrical"};
return a;
}
public static void main(String[] args)
{
new UpdateTeacherDetails();
}
public void updateIntoDB()
{
String name,address,email,classXII, fatherName, dob,phone,classX,aadhar;
String education,department,empID;
empID=(String)employeeIDField.getSelectedItem();
name=nameField.getText();
address=addressField.getText();
email=emailField.getText();
classXII=classXIIField.getText();
fatherName=fatherField.getText();
dob=DateFormat.getDateInstance().format(DOB.getDate());
phone=phoneField.getText();
classX=classXField.getText();
aadhar=aadharField.getText();
department=(String)departmentComboBox.getSelectedItem();
education=(String)educationComboBox.getSelectedItem();
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
c = DriverManager.getConnection("jdbc:mysql://localhost:3306/universitymanagementsystem", "root", "root");
//name+"','"+fatherName+"','"+empID+"','"+dob+"','"+address+"','"+phone+"','"+email+"','"+classX+"','"+classXII+"','"+aadhar+"','"+course+"','"+education+"','"+department
st=c.createStatement();
String insertQuery="UPDATE teacher SET name ='"+name+"',fatherName='"+fatherName+"',dob='"+dob+"',address='"+address+"',phone='"+phone+"',email='"+email+"',classX='"+classX+"',classXII='"+classXII+"',aadhar='"+aadhar+"',education='"+education+"',department='"+department+"' WHERE empID ='"+empID+"';";
st.execute(insertQuery);
JOptionPane.showMessageDialog(null, "inserted Successfully");
this.setVisible(false);
c.close();
}
catch (Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.toString());
}
}
public String[] getEmpIDFromDB()
{
String a[];
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
c = DriverManager.getConnection("jdbc:mysql://localhost:3306/universitymanagementsystem", "root", "root");
//name varchar(30), fatherName varchar(30),rollNo varchar (10),dob varchar(40),address varchar(100),phone varchar(30),email varchar(20),classX varchar(30),classXII varchar(30),aadhar varchar(30),course varchar(30),branch varchar(30));
st=c.createStatement();
String selectAllQuery="select empID from teacher;";
rs=st.executeQuery(selectAllQuery);
int size=0;
ArrayList<String> s=new ArrayList<>();
while (rs.next())
{
size++;
s.add(rs.getString(1));
}
a=new String[size];
for(int i =0;i<size;i++)
{
a[i] = s.get(i);
}
c.close();
return a;
}
catch (Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.toString());
}
a=null;
return a;
}
public void actionPerformed(ActionEvent a)
{
if(a.getSource()==submitBtn)
{
updateIntoDB();
}
else if(a.getSource()==cancleBtn)
{
// cancleBtn
this.setVisible(false);
}
}
}