0% found this document useful (0 votes)
6 views1 page

BTN Add Action Performed

Uploaded by

Gia Huy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

BTN Add Action Performed

Uploaded by

Gia Huy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

private void btnAddActionPerformed(java.awt.event.

ActionEvent evt) {
// TODO add your handling code here:
Connection conn = null;
PreparedStatement statement = null;
String maSv = txtMasv.getText();
String hoTen = txtHoten.getText();
String email = txtEmail.getText();
String diaChi = txtDiachi.getText();
String lop = txtLop.getText();
try {
// Mo ket noi den CSDL
conn = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
//Them du lieu vao CSDL
String sql = "INSERT INTO ctt24_student(masv, hoten,email, diachi, lopsv)" +
"VALUES(?,?,?,?,?)";
statement = (PreparedStatement) conn.prepareStatement(sql);
statement.setString(1, maSv);
statement.setString(2, hoTen);
statement.setString(3, email);
statement.setString(4, diaChi);
statement.setString(5, lop);
statement.execute();
} catch (SQLException ex) {
Logger.getLogger(StudentFrame.class.getName()).log(Level.SEVERE, null, ex);
} finally {
//Dong ket noi
if (conn != null){
try {
conn.close();
} catch (SQLException ex) {
Logger.getLogger(StudentFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (statement != null){
try {
statement.close();
} catch (SQLException ex) {
Logger.getLogger(StudentFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}

You might also like