2015-09-25 80 views
-6
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {           

     // TODO add your handling code here: 

     try{ 

      String CompanyID=ComID.getText(); 

      String User_name=Username.getText(); 

      String password=Password.getText(); 

      String post_held=jTextField2.getText(); 

      String azu="update staffs set StaffID= 

'"+CompanyID+"',UserName='"+User_name+"',Password='"+password+"','Post_held="+post_held+"'where StaffID='"+CompanyID+"' "; 

      //azucar="update staffs set StaffID= ?,?,?,?"; 

      az.psst = az.conn.prepareStatement(azu); 

      az.psst.execute(azu); 

      JOptionPane.showMessageDialog(null, 
      "Updated!","Frsc",JOptionPane.INFORMATION_MESSAGE); 

     }catch (Exception e){ 

      JOptionPane.showMessageDialog(null, e); 

     }deb(); 


    }      

+0

你想問什麼? –

+0

@sambayour你可以提供一些背景知道發生了什麼以及你在問什麼?您還可以通過使用4個空格縮進每行來使代碼更具吸引力。 – WhiteViking

回答

0

'Post_held="+post_held+"'where應該
Post_held='"+post_held+"' where


在不同的音符:使用字符串連接一樣,不要建立一個SQL語句,否則你會把自己暴露給攻擊SQL Injection,這將允許攻擊者刪除/竊取你的數據。

使用帶有參數標記(?)的PreparedStatement並設置語句對象上的值。