我正在尝试在 Java Netbeans IDE 中为我的桌面应用程序运行数据代码的修改,但问题是在某人有权修改数据之前,我想通过在另一个中提供用户名和密码来确保该人已获得授权JFrame 形式。如果验证了用户名和密码,那么只有修改任务才会成功;否则用户将收到身份验证不成功的错误。我试图在我的主表单中编写代码,但是当我想在身份验证表单的 button_click 事件中编写代码时,可以吗?我试过了,但它说你需要在这个类中声明那个类的变量,请帮忙..??
这是登录表单,我想验证用户是否在验证用户后修改数据我想允许他运行修改部分....
private void loginActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource()==login){
if((tb_uid.getText().equals(""))||(tb_pwd.getText().equals(""))){
JOptionPane.showMessageDialog(rootPane, "Please Enter Valid UserName and Password!");
}else{
DBUtil util = new DBUtil();
String user1 = "";
String pass1 = "";
try {
Connection con = util.getConnection();
PreparedStatement stmt = con.prepareStatement("SELECT * FROM login where username=?");
ResultSet res;
String value1 = tb_uid.getText();
String value2 = tb_pwd.getText();
stmt.setString(1, "" + (value1));
res = stmt.executeQuery();
while (res.next()) {
user1 = res.getString("username");
pass1 = res.getString("password");
}
if (value1.equals(user1) && value2.equals(pass1)) {
JOptionPane.showMessageDialog(null, "AUTHENTICATION SUCCESSFUL!");
try {
Connection con = util.getConnection();
PreparedStatement stmtn = con.prepareStatement("update soil_det set[weight]=?,[note_state]=?,[dm_state]=?,[1]=?,[2]=?,[5]=?,[10]=?,[20]=?,[50]=?,[100]=?,[500]=?,[1000]=? FROM [CNV].[dbo].[soil_det] where rm_id=? and box_no =?");
String rmn = (tf_rm_id.getText() == null || tf_rm_id.getText().equals("")) ? "0" : tf_rm_id.getText();
String an = (txtRe1.getText().trim() == null || txtRe1.getText().equals("")) ? "0" : txtRe1.getText();
String bn = (txtRs2.getText().trim() == null || txtRs2.getText().equals("")) ? "0" : txtRs2.getText();
String cn = (txtRs5.getText().trim() == null || txtRs5.getText().equals("")) ? "0" : txtRs5.getText();
String dn = (txtRs10.getText().trim() == null || txtRs10.getText().equals("")) ? "0" : txtRs10.getText();
String en = (txtRs20.getText().trim() == null || txtRs20.getText().equals("")) ? "0" : txtRs20.getText();
String fn = (txtRs50.getText().trim() == null || txtRs50.getText().equals("")) ? "0" : txtRs50.getText();
String gn = (txtRs100.getText().trim() == null || txtRs100.getText().equals("")) ? "0" : txtRs100.getText();
String hn = (txtRs500.getText().trim() == null || txtRs500.getText().equals("")) ? "0" : txtRs500.getText();
String in = (txtRs1000.getText().trim() == null || txtRs1000.getText().equals("")) ? "0" : txtRs1000.getText();
String bnn = (txtboxno.getText().trim() == null || txtboxno.getText().equals("")) ? "0" : txtboxno.getText();
String bwn = (txtboxwgt.getText().trim() == null || txtboxwgt.getText().equals("")) ? "0" : txtboxwgt.getText();
Object nsn = (cbnotstat.getSelectedItem() == null || cbnotstat.getSelectedItem().equals("")) ? "0" : cbnotstat.getSelectedItem();
Object dsn = (cbdmnstat.getSelectedItem() == null || cbdmnstat.getSelectedItem().equals("")) ? "0" : cbdmnstat.getSelectedItem();
stmtn.setString(1, "" + (bwn));
stmtn.setString(2, "" + nsn);
stmtn.setString(3, "" + dsn);
stmtn.setInt(4, Integer.parseInt(an));
stmtn.setInt(5, Integer.parseInt(bn));
stmtn.setInt(6, Integer.parseInt(cn));
stmtn.setInt(7, Integer.parseInt(dn));
stmtn.setInt(8, Integer.parseInt(en));
stmtn.setInt(9, Integer.parseInt(fn));
stmtn.setInt(10, Integer.parseInt(gn));
stmtn.setInt(11, Integer.parseInt(hn));
stmtn.setInt(12, Integer.parseInt(in));
stmtn.setString(13, "" + (rmn));
stmtn.setInt(14, Integer.parseInt(bnn));
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
else {
JOptionPane.showMessageDialog(this, "AUTHERNTICATION UNSUCCESSFUL", "Error", JOptionPane.ERROR_MESSAGE);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
this.dispose();
}
}
}
但主要问题是来自另一种形式的修改部分..