1. 程式人生 > >Can not issue data manipulation statements with executeQuery()的解決方案

Can not issue data manipulation statements with executeQuery()的解決方案

cut als data result resultset 圖片 只需要 方法 9.png

技術分享圖片

Can not issue data manipulation statements with executeQuery() 報錯的解決方案: 把“ResultSet rs = statement.executeQuery(sql);”改成“boolean rs = statement.execute(sql);”就不會報錯了。 原因是查詢sql是把查詢的結果都打印出來,修改更新(update)只需要判斷是否執行成功,不需要打印結果, 所以這裏不能用executeQuery()方法。

技術分享圖片

上面打印的結果顯示false,查看數據庫的值已經被修改了。把“ statement.execute(sql)”改成

“ statement.executeUpdate(sql);”就可以啦~

Can not issue data manipulation statements with executeQuery()的解決方案