在java中此更新查询有什么问题? [英] What is wrong with this update query in java?

查看:113
本文介绍了在java中此更新查询有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的托管bean中进行更新查询。这是代码:

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());
   }



我看到参数设置正确,看起来像我的错误查询。它进入catch块。另外,我不知道如何看到堆栈跟踪,e.printStackTrace不工作在这里我怎么能看到它?

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?

感谢

推荐答案

尝试使用executeUpdate executeQuery。我在执行数据库更新时遇到executeQuery的奇怪问题。

Try using executeUpdate instead of executeQuery. I have seen strange problem with executeQuery while doing a db update.

这篇关于在java中此更新查询有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆