-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveEmployee.java
More file actions
145 lines (119 loc) · 3.48 KB
/
RemoveEmployee.java
File metadata and controls
145 lines (119 loc) · 3.48 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
package EmployeM2Packege;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
public class RemoveEmployee extends JFrame implements ActionListener{
Choice cempid;
JLabel name,phone,email;
JButton Delete,back;
public RemoveEmployee() {
getContentPane().setBackground(Color.white);
setLayout(null);
JLabel lempid=new JLabel("Empid");
lempid.setBounds(50,100,100,30);
add(lempid);
cempid=new Choice();
cempid.setBounds(150,100,100,30);
add(cempid);
try {
JdbcClass jd=new JdbcClass();
PreparedStatement pre = jd.con.prepareStatement("select * from addemp1");
ResultSet rs = pre.executeQuery();
while(rs.next()) {
cempid.add(rs.getString("empid"));
}
System.out.println("Execute success");
}
catch(Exception ex) {
System.out.println("Execute not success");
}
JLabel lname=new JLabel("Name");
lname.setBounds(50,150,100,30);
add(lname);
name=new JLabel();
name.setBounds(180,150,100,30);
add(name);
JLabel lphone=new JLabel("Phoneno");
lphone.setBounds(50,200,100,30);
add(lphone);
phone=new JLabel();
phone.setBounds(180,200,100,30);
add(phone);
JLabel lemail=new JLabel("EmailId");
lemail.setBounds(50,250,100,30);
add(lemail);
email=new JLabel();
email.setBounds(180,250,100,30);
add(email);
try {
JdbcClass jd=new JdbcClass();
String empid;
PreparedStatement pre = jd.con.prepareStatement("select * from addemp1 where empid='"+cempid.getSelectedItem()+"'");
ResultSet rs = pre.executeQuery();
while(rs.next()) {
name.setText(rs.getString("name"));
phone.setText(rs.getString("phoneno"));
email.setText(rs.getString("emails"));
}
System.out.println("Execute success");
}
catch(Exception ex) {
System.out.println("Execute not success");
}
cempid.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent ie) {
try {
JdbcClass jd=new JdbcClass();
String empid;
PreparedStatement pre = jd.con.prepareStatement("select * from addemp1 where empid='"+cempid.getSelectedItem()+"'");
ResultSet rs = pre.executeQuery();
while(rs.next()) {
name.setText(rs.getString("name"));
phone.setText(rs.getString("phoneno"));
email.setText(rs.getString("emails"));
}
System.out.println("Execute success");
}
catch(Exception ex) {
System.out.println("Execute not success");
}
}
});
Delete=new JButton("Delete");
Delete.setBounds(250,300,100,30);
Delete.setBackground(Color.red);
Delete.addActionListener(this);
add(Delete);
back=new JButton("Back");
back.setBounds(400,300,100,30);
back.setBackground(Color.BLUE);
back.addActionListener(this);
add(back);
setSize(700,600);
setLocation(100,50);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==Delete) {
try {
JdbcClass jd=new JdbcClass();
PreparedStatement pre = jd.con.prepareStatement("delete from addemp1 where empid='"+cempid.getSelectedItem()+"'");
pre.executeUpdate();
JOptionPane.showMessageDialog(null, "successfully Delete");
setVisible(false);
new Home();
}
catch(Exception e1) {
System.out.println("not delete");
}
}
else {
setVisible(false);
new Home();
}
}
public static void main(String[] args) {
new RemoveEmployee();
}
}