这个更新查询在java中有什么问题?

时间:2013-07-10 09:09:59

标签: java database jsf java-ee

我正在尝试在托管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在这里不起作用我怎么能看到它?可以帮忙吗?

由于

1 个答案:

答案 0 :(得分:0)

尝试使用executeUpdate而不是executeQuery。我在执行db更新时遇到了executeQuery的奇怪问题。

相关问题