问题描述
我正在尝试在托管bean中进行更新查询.这是代码:
try { PreparedStatement checkDB1 = (PreparedStatement) con.prepareStatement("update pocket set balance=? where username=?"); checkDB1.setDouble(1, (double) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("selectedUserBalance")-total); //This returns the desired result checkDB1.setString(2, (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("selectedAccountIban")); //Returns the desired result checkDB1.executeQuery(); } catch (SQLException e) { System.err.println("SQLState: " + ((SQLException)e).getSQLState()); System.out.println("SQLState: " +((SQLException)e).getSQLState()); }
我看到参数已正确设置,看起来我的查询中存在错误.它进入捕获块.另外,我不知道如何看到堆栈跟踪,e.printstacktrace在这里不起作用?可以帮助吗?
谢谢
推荐答案
尝试使用executeupdate而不是executeQuery.我在执行DB更新时看到了executequery的奇怪问题.
问题描述
I am trying to make an update query in my managed bean. Here is the code:
try { PreparedStatement checkDB1 = (PreparedStatement) con.prepareStatement("update pocket set balance=? where username=?"); checkDB1.setDouble(1, (double) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("selectedUserBalance")-total); //This returns the desired result checkDB1.setString(2, (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("selectedAccountIban")); //Returns the desired result checkDB1.executeQuery(); } catch (SQLException e) { System.err.println("SQLState: " + ((SQLException)e).getSQLState()); System.out.println("SQLState: " +((SQLException)e).getSQLState()); }
I see that parameters are set correctly, looks like there is an error in my query. It enters the catch block. Also, i don't know how to see the stack trace, e.printStackTrace does not work here how can i see it? Can anyne help?
Thanks
推荐答案
Try using executeUpdate instead of executeQuery. I have seen strange problem with executeQuery while doing a db update.