這是我的代碼來更新學生attendance.But在執行期間此方法返回SQL COMMAND NOT PROPERLY ENDED ERROR。sql命令沒有正確結束錯誤
private void updateAttendance(){
MyQuery mq=new MyQuery();
Connection con=mq.getConnection();
Statement st;
ResultSet rs;
try{
st=con.createStatement();
rs=st.executeQuery("Select STU_ID FROM STUDENT WHERE NAME='"+cmbName.getSelectedItem()+"'");
if(rs.next()){
//System.out.println("getting student name");
int id=rs.getInt("STU_ID");
String sql="UPDATE STUDENT SET SUBJECT='"+cmbSub.getSelectedItem()+"',ATTENDANCE='";
//sql+="ATTENDANCE='"+"";
if(rdbtnPresent.isSelected())
sql+= "'"+Atdnc[0]+"',";
else
sql+= "'"+Atdnc[1]+"',";
sql+="WHERE STU_ID='"+id+"'";
st.executeUpdate(sql);
//cmbName.removeAllItems();
}
}catch(SQLException ex){
Logger.getLogger(Student.class.getName()).log(Level.SEVERE, null, ex);
}
}
你可以調試'sql'值,並告訴我們你得到什麼? Btw非常大的SQL注入警告。使用參數化語句。 Sql注入警告https://xkcd.com/327/ –