-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalab28.java
More file actions
107 lines (84 loc) · 3.09 KB
/
Copy pathjavalab28.java
File metadata and controls
107 lines (84 loc) · 3.09 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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
class javadriver extends JFrame implements ActionListener {
JTextField txt1, txt2, txt3, txt4;
JButton b1, b2, b3;
public javadriver() {
setTitle("RECORD CREATOR");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(600, 300);
setResizable(true);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4, 2, 10, 10));
panel.add(new JLabel("Enter Name:"));
txt1 = new JTextField(15);
panel.add(txt1);
panel.add(new JLabel("Enter Code:"));
txt2 = new JTextField(15);
panel.add(txt2);
panel.add(new JLabel("Enter Designation:"));
txt3 = new JTextField(15);
panel.add(txt3);
panel.add(new JLabel("Enter Salary:"));
txt4 = new JTextField(15);
panel.add(txt4);
b1 = new JButton("SUBMIT");
b1.addActionListener(this);
panel.add(b1);
b2 = new JButton("RESET");
b2.addActionListener(this);
panel.add(b2);
b3 = new JButton("EXIT");
b3.addActionListener(this);
panel.add(b3);
panel.add(new JLabel());
panel.add(new JLabel());
add(panel);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
try {
if (ae.getSource() == b1) {
String name = txt1.getText();
String code = txt2.getText();
String designation = txt3.getText();
Double salary = Double.parseDouble(txt4.getText());
String url = "jdbc:mysql://localhost:3306/AI";
String user = "root";
String password = "12345";
String Query = "INSERT INTO Employee(name,code,designation,salary) VALUES (?, ?, ?, ?)";
Connection conn = DriverManager.getConnection(url, user, password);
PreparedStatement stmt = conn.prepareStatement(Query);
stmt.setString(1, name);
stmt.setString(2, code);
stmt.setString(3, designation);
stmt.setDouble(4, salary);
stmt.executeUpdate();
JOptionPane.showMessageDialog(this, "Record Inserted Successfully");
// Close resources
stmt.close();
conn.close();
}
else if (ae.getSource() == b2) {
txt1.setText("");
txt2.setText("");
txt3.setText("");
txt4.setText("");
txt1.requestFocus();
}
else if (ae.getSource() == b3) {
System.exit(0);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
public class javalab28 {
public static void main(String[] args) {
new javadriver();
}
}