anh chị ơi, giúp e chạy demo edit này với ạ, e chạy bị lỗi ,
package Quanlibaiguixe;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Edit extends JFrame{
private JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9;
private JButton ok;
private int LUOTGUIXE;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Edit frame = new Edit();
frame.setVisible(true);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
}
public Edit() {
initbgx();
initEdit();
}
public void initEdit() {
this.setSize(400, 300);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setTitle("Edit");
this.setBounds(750, 400, 400, 300);
JPanel contentPane=new JPanel();
contentPane.setLayout(null);
this.setContentPane(contentPane);
JLabel luotguixe=new JLabel("LUOTGUIXE:");
luotguixe.setBounds(40, 70, 77, 14);
t1 = new JTextField();
t1.setBounds(130, 70, 160, 20);
contentPane.add(luotguixe);
contentPane.add(t1);
JLabel giovao=new JLabel("GIOVAO:");
giovao.setBounds(40,105, 77, 14);
t2 = new JTextField();
t2.setBounds(130, 105, 160, 20);
contentPane.add(giovao);
contentPane.add(t2);
JLabel loaixe=new JLabel("LOAIXE:");
loaixe.setBounds(40,140, 77, 14);
t3 = new JTextField();
t3.setBounds(130, 140, 160, 20);
contentPane.add(loaixe);
contentPane.add(t3);
JLabel bienso=new JLabel("BIENSO:");
bienso.setBounds(40,175, 77, 14);
t4 = new JTextField();
t4.setBounds(130, 175, 160, 20);
contentPane.add(bienso);
contentPane.add(t4);
JLabel giora=new JLabel("GIORA:");
giora.setBounds(40,210, 77, 14);
t5 = new JTextField();
t5.setBounds(130, 210, 160, 20);
contentPane.add(giora);
contentPane.add(t5);
JLabel gia=new JLabel("GIA:");
gia.setBounds(40,245, 77, 14);
t6 = new JTextField();
t6.setBounds(130, 245, 160, 20);
contentPane.add(gia);
contentPane.add(t6);
JLabel manv=new JLabel("MANV:");
giovao.setBounds(40,280, 77, 14);
t7 = new JTextField();
t7.setBounds(130, 280, 160, 20);
contentPane.add(manv);
contentPane.add(t7);
JLabel mabai=new JLabel("MABAI:");
mabai.setBounds(40,315, 77, 14);
t8 = new JTextField();
t8.setBounds(130, 315, 160, 20);
contentPane.add(mabai);
contentPane.add(t8);
JLabel mave=new JLabel("MAVE:");
mave.setBounds(40,350, 77, 14);
t9 = new JTextField();
t9.setBounds(130, 350, 160, 20);
contentPane.add(mave);
contentPane.add(t9);
ok=new JButton("OK");
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int LUOTGUIXE = Integer.parseInt(t1.getText().trim());
String GIOVAO = String.valueOf(t2.getText());
String LOAIXE = t3.getText();
String BIENSO = t4.getText();
String GIORA =t5.getText();
String GIA = t6.getText();
int MANV = Integer.parseInt(t7.getText().trim());
int MABAI = Integer.parseInt(t8.getText().trim());
int MAVE =Integer.parseInt(t9.getText().trim());
// Insert to database:
try {
Class.forName("com.mysql.jdbc.Driver");
String db_url = "jdbc:mysql://192.168.10.1/SinhVien";
String db_user = "sinhvien";
String db_pass = "12345678";
Connection conn = null;
conn = DriverManager.getConnection(db_url, db_user, db_pass);
String sqlInsert = "UPDATE luotguixe SET GIOVAO = ?, LOAIXE =?,BIENSO = ?,GIORA=?,GIA=?,MANV=?,MABAI=?,MAVE=? WHERE LUOTGUIXE = ? ";
PreparedStatement stmt2 = conn.prepareStatement(sqlInsert);
stmt2.setString(1, GIOVAO);
stmt2.setString(2, LOAIXE);
stmt2.setString(3, BIENSO);
stmt2.setString(4, GIORA);
stmt2.setString(5, GIA);
stmt2.setInt(6, MANV);
stmt2.setInt(7, MABAI);
stmt2.setInt(8, MAVE);
stmt2.setInt(9, LUOTGUIXE);
stmt2.executeUpdate();
stmt2.close();
conn.close();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
// e1.printStackTrace();
JOptionPane.showMessageDialog(null, "Driver Error!");
} catch (SQLException e1) {
// TODO Auto-generated catch block
// e1.printStackTrace();
JOptionPane.showMessageDialog(null, "SQL Error!");
}
// Notify
JOptionPane.showMessageDialog(null, "Successfully");
}
});
}
public void initbgx() {
t1.setText(String.valueOf(LUOTGUIXE));
try {
Class.forName("com.mysql.jdbc.Driver");
String db_url = "jdbc:mysql://127.0.0.1/bgx";
String db_user = "ntminh2";
String db_pass = "123456";
Connection conn = null;
conn = DriverManager.getConnection(db_url, db_user,db_pass);
Statement stmt = null;
stmt = conn.createStatement();
String sql;
sql = "SELECT LUOTGUIXE,GIOVAO,LOAIXE,BIENSO,GIORA,GIA,MANV,MAVE,MABAI FROM luotguixe WHERE LUOTGUIXE = '"+ LUOTGUIXE + "'";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
// Retrieve by column name
String GIOVAO = String.valueOf(rs.getTime("GIOVAO"));
String LOAIXE = rs.getString("LOAIXE");
String BIENSO = rs.getString("BIENSO");
String GIORA =String.valueOf( rs.getTime("GIORA"));
String GIA = rs.getString("GIA");
String MANV = String.valueOf(rs.getInt("MANV"));
String MABAI = String.valueOf(rs.getInt("MABA"));
String MAVE = String.valueOf(rs.getInt("MAVE"));
t1.setEditable(false);
t2.setText(GIOVAO);
t3.setText(LOAIXE);
t4.setText(BIENSO);
t5.setText(GIORA);
t6.setText(GIA);
t7.setText(MANV);
t8.setText(MABAI);
t4.setText(MAVE);
}
rs.close();
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}