2014-05-03 24 views
-2
try { 

    if (txtID.getText().isEmpty() 
      || txtLname.getText().isEmpty() 
      || txtFname.getText().isEmpty() 
      || txtMname.getText().isEmpty() 
      || jTextField1.getText().isEmpty() 
      || jTextField2.getText().isEmpty() 
      || jTextField3.getText().isEmpty()) 

    { 
     JOptionPane.showMessageDialog(null, "Fill Up All The Fields"); 
    } else { 
     if (btnReg.getText().equals("REGISTER")) { 
      stm.execute("insert into tblregular(ID, LNAME, FNAME, MNAME, VLEAVE, SLEAVE, TOTAL) values" 
          + "('" + txtID.getText().trim() + "'" 

          + ",'" + txtLname.getText().trim().toUpperCase() + "'" 
          + ",'" + txtFname.getText().trim().toUpperCase() + "'" 
          + ",'" + txtMname.getText().trim().toUpperCase() + "'" 
          + ",'" + jTextField1.getText().trim().toUpperCase() + "'" 
          + ",'" + jTextField2.getText().trim().toUpperCase() + "'" 
          + ",'" + jTextField3.getText().trim().toUpperCase() + "'" 


        JOptionPane.showMessageDialog(null, "Registration Successfull"); 
     } else { 
      txtID.setText(""); 
      txtLname.setText(""); 
      txtFname.setText(""); 
      txtMname.setText(""); 
      jTextField1.setText(""); 
      jTextField2.setText(""); 
      txtMname.setText(""); 

     } 
    } 
} catch (Exception e) { 
    System.out.println(e); 
} 

在行+ ",'"+jTextField3.getText().trim().toUpperCase()+"'" - 它说Expected ')'我的错误是什么?该怎么做,要添加什么,要删除什么,我不能帮助我的自我。请帮助我。预期')'(使用netbeans)

+0

所以这是一个很好的理由,为什么你不应该使用字符串连接来构建查询 - 它不仅是容易受到SQL注入,它可以导致这样的头痛。 – Makoto

+0

因为在我的大学里,这是他们教的先生。我能做些什么来解决这个问题? – user3598225

+1

我同意netbeans,你应该关闭你已经打开的括号 – donfuxx

回答

1

您需要完成您传递给stm.execute()的字符串以及该语句之后所需的分号。该字符串缺少关于插入值的关闭paren。

3

您尚未关闭执行方法的括号。

stm.execute("insert into tblregular(ID, LNAME, FNAME, MNAME, VLEAVE, SLEAVE, TOTAL) values" 
         + "('"+txtID.getText().trim()+"'" 

         + ",'"+txtLname.getText().trim().toUpperCase()+"'" 
         + ",'"+txtFname.getText().trim().toUpperCase()+"'" 
         + ",'"+txtMname.getText().trim().toUpperCase()+"'" 
         + ",'"+jTextField1.getText().trim().toUpperCase()+"'" 
         + ",'"+jTextField2.getText().trim().toUpperCase()+"'" 
         + ",'"+jTextField3.getText().trim().toUpperCase()+"'"); 

,并尝试使用PreparedStatement这里是example