- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetails.java
More file actions
Latest commit
120 lines (106 loc) · 4.38 KB
/
Copy pathDetails.java
File metadata and controls
120 lines (106 loc) · 4.38 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
importjava.util.*;
importjava.sql.*;
importjavax.swing.*;
importjava.awt.event.*;
classDetailsextendsJFrameimplementsActionListener {
JButtondisplay;
JLabeld, na, nat, e, y, s, e1, heading;
JTextFielddesignation, nationality, name, empid, year, salary, e2;
Details() {
super("EMPLOYEE DETAILS");
this.display = newJButton("DISPLAY");
this.d = newJLabel("DESIGNATION");
this.na = newJLabel("NAME");
this.nat = newJLabel("NATIONALITY");
this.e = newJLabel("EMP ID");
this.y = newJLabel("YEAR");
this.s = newJLabel("SALARY");
this.heading = newJLabel("EMPLOYEE DATA");
this.e1 = newJLabel("ENTER ID");
this.designation = newJTextField(10);
this.nationality = newJTextField(10);
this.name = newJTextField(10);
this.empid = newJTextField(10);
this.year = newJTextField(10);
this.salary = newJTextField(10);
this.e2 = newJTextField(10);
this.add(this.display);
this.add(this.d);
this.add(this.na);
this.add(this.nat);
this.add(this.e);
this.add(this.y);
this.add(this.s);
this.add(this.heading);
this.add(this.e1);
this.add(this.designation);
this.add(this.nationality);
this.add(this.name);
this.add(this.empid);
this.add(this.year);
this.add(this.salary);
this.add(this.e2);
this.setLayout(null);
this.heading.setBounds(20, 50, 150, 20);
this.e1.setBounds(20, 70, 150, 20);
this.e2.setBounds(20, 90, 150, 20);
this.e.setBounds(20, 110, 150, 20);
this.empid.setBounds(20, 130, 150, 20);
this.na.setBounds(20, 150, 150, 20);
this.name.setBounds(20, 170, 150, 20);
this.d.setBounds(20, 190, 150, 20);
this.designation.setBounds(20, 210, 150, 20);
this.nat.setBounds(20, 230, 150, 20);
this.nationality.setBounds(20, 250, 150, 20);
this.y.setBounds(20, 270, 150, 20);
this.year.setBounds(20, 290, 150, 20);
this.s.setBounds(20, 310, 150, 20);
this.salary.setBounds(20, 330, 150, 20);
this.display.setBounds(200, 150, 150, 50);
this.setVisible(true);
this.setSize(500, 300);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.display.addActionListener(this);
}
publicvoidactionPerformed(ActionEventae) {
try {
Strings = ae.getActionCommand();
intemp, e3, numrows = 0;
if ((s.equals("DISPLAY")) == true) {
emp = Integer.parseInt(this.e2.getText());
Class.forName("com.mysql.cj.jdbc.Driver");
Connectioncon = DriverManager.getConnection("jdbc:mysql://localhost:3306/company", "root", "root");
Statementstm = con.createStatement();
Stringqry = "select * from employee order by salary";
ResultSetrs = stm.executeQuery(qry);
while (rs.next()) {
numrows++;
if (numrows == emp) {
this.empid.setText(Integer.toString(rs.getInt(1)));
this.name.setText(rs.getString(2));
this.designation.setText(rs.getString(3));
this.nationality.setText(rs.getString(4));
this.year.setText(Integer.toString(rs.getInt(5)));
this.salary.setText(Double.toString(rs.getDouble(6)));
}
}
if (numrows == 0) {
this.empid.setText("Data not found");
this.name.setText("Data not found");
this.designation.setText("Data not found");
this.nationality.setText("Data not found");
this.year.setText("Data not found");
this.salary.setText("Data not found");
}
stm.close();
rs.close();
con.close();
}
} catch (ClassNotFoundException | SQLExceptione) {
System.out.println("Caught Exception:" + e);
}
}
publicstaticvoidmain(Stringargs[]) {
Detailsd1 = newDetails();
}
}