我在做更改密碼我需要更新舊密碼。基於舊密碼,我需要得到記錄,然後更新記錄,但這裏是我試圖更新它時,我得到了創紀錄的問題顯示在消息空無法在java servlet中執行更新查詢
我的代碼:
public String ResetPwd(String NewPwd, String name,String oldpwd)
{
String Pass="Select * from Users where Password='"+oldpwd+"' and UserId='"+name+"'";
String UpdateQuery="update Users set Password='"+NewPwd+"' where UserId='"+name+"'";
try{
currentCon = ConnectionManager.getConnection();
st=currentCon.createStatement();
rs = st.executeQuery(Pass);
if(rs.next())
{
PreparedStatement ps=currentCon.prepareStatement(UpdateQuery);
int i=ps.executeUpdate();
ps.close();
if(i>=1)
{
msg="Password Changed Successfully";
}
}
else{
msg="Old Password Not Match Please Enter Correct Password..!";
return msg;
}
}catch(Exception ex){}
return msg;
}
你剛剛刪除了你的最後一個問題然後轉貼......爲什麼?哦,你還沒有在'catch'塊中添加'e.printStackTrace()'....可能想這麼做,有很多重要信息可以從簡單的堆棧跟蹤中獲得js – CraigR8806
爲什麼要執行2個executeUpdate命令?第二個是在ps.close()之後啓動的,這是行不通的。 – Galcoholic