嗨,有人能幫我弄清楚我的愚蠢錯誤在哪裏。 我試圖找出在互聯網上,但無法找到最佳解決方案。我有一個jsp和java控制器,我應該可以從數據庫中刪除記錄,以下是我的代碼。任何有助於將承認使用jsp和servlet刪除函數
public void doDel(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, InstantiationException, IllegalAccessException{
try {
HttpSession session = request.getSession(true);
messageBean mbean = new messageBean();
int id = mbean.getMesId();
String sql;
sql = "DELETE * from message where id =?";
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url);
st = conn.createStatement();
ps = conn.prepareStatement(sql);
ps.setInt(1, id);
ps.executeUpdate();
conn.commit();
conn.close();
只需將id連接到字符串。 sql =「Delete * from message where id =」+ id; – JNL
'嗨,有人能幫我弄清楚我的愚蠢的錯誤在哪裏,對不起,我們手中沒有魔法球。什麼是例外?你在期待什麼?當前代碼的行爲如何? –
@JNL由於SQL注入,您在註釋中提到的方法可能是安全問題。 – Bhushan