Return value of 'statement.executeUpdate();' - Mailing list pgsql-jdbc

From Neil Kidd
Subject Return value of 'statement.executeUpdate();'
Date
Msg-id 4.3.2.7.2.20010417171234.00a9cc70@ms.webfactory.co.uk
Whole thread Raw
List pgsql-jdbc
Hi,
I am developing a Servlet based app where I am permitting users to delete
their own accounts.
(PostgreSQL 7.03 and jdbc7.0-1.2.jar)

I am using the following function - if I understand correctly the call
"statement.executeUpdate();"
should return an int that indicates the number of rows affected in the
table. However whatever parameters are supplied, the call always returns 1.
Is this correct?

private void deleteAccount(Connection dbCon, HttpServletRequest req)
{
     PreparedStatement statement = null;
     String                     template   = "DELETE FROM tbl_users "
                                                    + "WHERE username = ? "
                                                    + "AND password = ? ;";
     int rowsChanged = -1;

     try
     {
       statement = dbCon.prepareStatement(template);
       statement.setString(1, this.mstr_userName);
       statement.setString(2, req.getParameter("curr_password"));
       rowsChanged = statement.executeUpdate();

       if(rowsChanged == 1)
       {
         //Send success message
         req.setAttribute("successMsg", "Your account was deleted.");
       }
       else if(rowsChanged != 1)
       {
         req.setAttribute("errorMsg", "Your account was not deleted.");
       }
     }
     catch(SQLException sqle)
     {
        System.err.println("sql exception" + sqle);
     }
     finally
     {
       closeStatement(statement);
     }
   }

Thanks in advance for any help or advice.
Regards,
Neil.
----------------------------------------------------------------
From:            Neil Kidd
Website:        http://www.kidd.org.uk
E-mail:           neil@kidd.org.uk
----------------------------------------------------------------


pgsql-jdbc by date:

Previous
From: Travis Bauer
Date:
Subject: Re: JDBC error in 7.0.3
Next
From: "Dave Cramer"
Date:
Subject: JDBC setObject