Return value of 'statement.executeUpdate();'

Поиск
Список
Период
Сортировка
От Neil Kidd
Тема Return value of 'statement.executeUpdate();'
Дата
Msg-id 4.3.2.7.2.20010417171234.00a9cc70@ms.webfactory.co.uk
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Travis Bauer
Дата:
Сообщение: Re: JDBC error in 7.0.3
Следующее
От: "Dave Cramer"
Дата:
Сообщение: JDBC setObject