Thursday 25 December 2008

Example Delete

int ok = JOptionPane.showConfirmDialog(null,"anda yakin hapus data \n Kode barang='"+jTextField1.getText()+"'","konfirmasi hapus data",JOptionPane.YES_NO_OPTION);
if (ok==0){
try{
Connection con=DriverManager.getConnection("jdbc:odbc:kitra","","");
String SQL="Delete from barang Where kd_brg='"+jTextField1.getText()+"'";
PreparedStatement st=con.prepareStatement(SQL);
st.executeUpdate();

JOptionPane.showMessageDialog(null,"data berhasil didelete");

jTextField1.setText("");
jTextField2.setText("");
jComboBox1.setSelectedItem("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField1.requestFocus();
} catch (SQLException se) {
JOptionPane.showMessageDialog(null,"gagal hapus data");

}
}

No comments:

Post a Comment