-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathInput.java
43 lines (40 loc) · 1.18 KB
/
Input.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
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Input extends JFrame implements ActionListener {
JLabel lid,lname,lage;
JTextField tid,tname,tage;
Connection c;
public Input(){
lid = new JLabel("ID");
tid = new JTextField(20);
lname = new JLabel("Name");
tname = new JTextField(30);
lage = new JLabel("Age");
tage = new JTextField(30);
setLayout(new FlowLayout());
add(lid);add(tid);
add(lname);add(tname);
add(lage);add(tage);
JButton jb = new JButton("Click me");
jb.addActionListener(this);
add(jb);
}
public void actionPerformed(ActionEvent ae){
try{
Connection c = DriverManager.getConnection("jdbc:mysql://localhost/college","root","");
System.out.println("connected");
Statement s = c.createStatement();
int id = Integer.parseInt(tid.getText());
String name = tname.getText();
int age = Integer.parseInt(tage.getText());
s.executeUpdate("insert into students values("+id+",'"+name+"',"+age+")");
}catch(SQLException se){}
}
public static void main(String [] op){
Input i = new Input();
i.setSize(300,300);
i.setVisible(true);
}
}