0

我正在尝试更新一个小型应用程序的用户配置文件。该程序正在从以前的会话中获取值,但我没有相应地更新。这是来自 UserDAO 的代码...

 public String updateUser(userBean user)throws Exception{

        System.out.println("Reached update user");

        String result = null;
        PreparedStatement stmtUpdate = null;

        //Create a Database Connection
        Connection con = ConnectionDAO.getJDBCConnection();
        try{
            System.out.println("Reached Try block");

            con.setAutoCommit(false);                   
            StringBuffer sbUpdate = new StringBuffer();

            System.out.println("String buffer created");

            sbUpdate.append("UPDATE user SET ");

            System.out.println(user.getUser()+ " details updating....");
            System.out.println(user.getFname()+ " ....");
            System.out.println(user.getLname()+ " ....");
            System.out.println(user.getMobileno()+ " ....");
            System.out.println(user.getEmail()+ " ....");
            System.out.println(user.getAddress()+ " ....");
            System.out.println(user.getDes()+ " ....");

            sbUpdate.append(" fname = '" + user.getFname() + "', ");
            sbUpdate.append(" lname = '" + user.getLname() + "', ");
            sbUpdate.append(" mobileno = '" + user.getMobileno() + "', ");
            sbUpdate.append(" email = '" + user.getEmail() + "', ");
            sbUpdate.append(" address = '" + user.getAddress() + "', ");
            sbUpdate.append(" des = '" + user.getDes() + "', ");

            sbUpdate.append(" where user='" + user.getUser() + "'" );

            stmtUpdate = con.prepareStatement(sbUpdate.toString());

            System.out.println("prepare statement created");

            int rows = stmtUpdate.executeUpdate();

            System.out.println("int rows has a value");

            if (rows != 1){
                result = FAILURE;
                System.err.println("Execute update error for user "+ user.getUser());

            }   

            result = SUCCESS;
            ConnectionDAO.commitJDBCConnection(con);
        }catch (SQLException ex){
            result = FAILURE;
            ConnectionDAO.rollbackJDBCConnection(con);

        }
        finally{
            ConnectionDAO.closeStatement(stmtUpdate);
            ConnectionDAO.closeJDBCConnection(con);
        }
        return result;  
    }

控制台显示...

INFO: Server startup in 460 ms
Oct 05, 2013 11:52:21 PM com.kbcss.DAO.UserDAO checkUser
INFO: Logging for user: sri
Reached update user
Reached Try block
String buffer created
sri details updating....
sri ....
sai ....
789456130 ....
123@qwer.com ....
123456 ....
qwert ....
prepare statement created

我所知道的是......

它显示直到“准备声明创建”,但后来会发生什么?没什么...程序终止了!!:( 任何想法都非常感谢..

我做错了吗?

PS..我是这个世界的新手!!!!

4

2 回答 2

1

问题似乎是语法错误

sbUpdate.append(" des = '" + user.getDes() + "', ");

最后尝试删除逗号。这也不是使用准备好的语句的正确方法。

于 2013-10-05T18:47:18.983 回答
1

不要WHERE在查询中的关键字前面放置逗号。它导致查询静默回滚并返回FAILURE

于 2013-10-05T18:47:52.633 回答