私はいくつかのメッセージをユーザーに適合させようとしています。彼が書かれたコードが実行されるべきだと確信していると言った場合、彼がjconformationボックスを拒否した場合、コードは実行されるべきではありません。データがコミットされます。これを停止するにはどうすればよいですか?コードを以下に示します...
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==jButton1){
JOptionPane.showConfirmDialog(rootPane, "Are You Sure You Want to Submit This Data and Genertate a New Remittance Id!");
DBUtil util = new DBUtil();
try {
Connection con = util.getConnection();
PreparedStatement stmt = con.prepareStatement("INSERT INTO dbo.bk_det(rm_id,bk_name,bk_branch,bk_add,bk_ref,ref_dt) VALUES (?,?,?,?,?,?)");
String rm = (tf_rm_id.getText().trim() == null || tf_rm_id.getText().equals("")) ? "0" : tf_rm_id.getText();
Object bkn = (cb_bkname.getSelectedItem() == null || cb_bkname.getSelectedItem().equals("")) ? "NILL" : cb_bkname.getSelectedItem();
Object bkbn = (cb_brname.getSelectedItem() == null || cb_brname.getSelectedItem().equals("")) ? "NILL" : cb_brname.getSelectedItem();
Object bkpln = (cb_plname.getSelectedItem() == null || cb_plname.getSelectedItem().equals("")) ? "NILL" : cb_plname.getSelectedItem();
String rf = (tb_bkref.getText().trim() == null || tb_bkref.getText().equals("")) ? "NILL" : tb_bkref.getText();
String rfdt = (tf_refdt.getText().trim() == null || tf_refdt.getText().equals("")) ? "NILL" : tf_refdt.getText();
stmt.setString(1, ""+(rm));
stmt.setString(2, ""+(bkn));
stmt.setString(3, ""+(bkbn));
stmt.setString(4, ""+(bkpln));
stmt.setString(5, ""+(rf));
stmt.setString(6, ""+(rfdt));
stmt.execute();
PreparedStatement stmt2 = con.prepareStatement("INSERT INTO bk_rep(rm_id, br_name, br_desig, br_pf, dt_rep, mob) VALUES (?,?,?,?,?,?)");
String rm1 = (tf_rm_id.getText().trim() == null || tf_rm_id.getText().equals("")) ? "0" : tf_rm_id.getText();
String brn = (tfbrname.getText().trim() == null || tfbrname.getText().equals("")) ? "NILL" : tfbrname.getText();
String brpf = (tf_brpf.getText().trim() == null || tf_brpf.getText().equals("")) ? "NILL" : tf_brpf.getText();
String brdes = (tf_brdes.getText().trim() == null || tf_brdes.getText().equals("")) ? "NILL" : tf_brdes.getText();
String brdtrep = (tf_rm_dt.getText().trim() == null || tf_rm_dt.getText().equals("")) ? "NILL" : tf_rm_dt.getText();
String brmob = (tf_brmob.getText().trim() == null || tf_brmob.getText().equals("")) ? "NILL" : tf_brmob.getText();
stmt2.setString(1, ""+(rm1));
stmt2.setString(2, ""+(brn));
stmt2.setString(3, ""+(brdes));
stmt2.setString(4, ""+(brpf));
stmt2.setString(5, ""+(brdtrep));
stmt2.setString(6, ""+(brmob));
stmt2.execute();
PreparedStatement stmt3 = con.prepareStatement("INSERT INTO bk_sec([bs_name],[bs_desig],[rm_id],[dt_rep]) VALUES (?,?,?,?)");
String rm2 = (tf_rm_id.getText().trim() == null || tf_rm_id.getText().equals("")) ? "0" : tf_rm_id.getText();
String sn = (tfsname.getText().trim() == null || tfsname.getText().equals("")) ? "NILL" : tfsname.getText();
String sdes = (tf_sdes.getText().trim() == null || tf_sdes.getText().equals("")) ? "NILL" : tf_sdes.getText();
String bsdtrep = (tf_rm_dt.getText().trim() == null || tf_rm_dt.getText().equals("")) ? "NILL" : tf_rm_dt.getText();
stmt3.setString(1, ""+(sn));
stmt3.setString(2, ""+(sdes));
stmt3.setString(3, ""+(rm2));
stmt3.setString(4, ""+(bsdtrep));
stmt3.execute();
JOptionPane.showMessageDialog(null, "COMMITED SUCCESSFULLY!");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
CalendarUtil cal=new CalendarUtil();
tf_rm_id.setText(cal.getRemId());
String datePrefix = new SimpleDateFormat("MMMM dd, YYYY").format(new Date());
tf_rm_dt.setText(datePrefix);
tb_bkref.setText("");
tf_refdt.setText("");
tf_brpf.setText("");
tf_brdes.setText("");
tf_brmob.setText("");
tfsname.setText("");
tf_sdes.setText("");
tfbrname.setText("");
tf_scity.setText("");
}
}