0

i am trying to update a user profile for a small application.. the program is taking values from the previous sessions but i's not updating accordingly. here is a code from 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;  
    }

console shows...

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

What i know is....

it shows till "prepare statement created" but what happen later? nothing...the program terminated!! :( any ideas are greatly appreciated..

did i do it wrong?

PS..i'm new to this world !!!!

4

2 に答える 2