Return value of 'statement.executeUpdate();'

From: Neil Kidd <neil(at)kidd(dot)org(dot)uk>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Return value of 'statement.executeUpdate();'
Date: 2001-04-17 16:25:32
Message-ID: 4.3.2.7.2.20010417171234.00a9cc70@ms.webfactory.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)kidd(dot)org(dot)uk
----------------------------------------------------------------

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2001-04-17 17:34:05 JDBC setObject
Previous Message Travis Bauer 2001-04-17 16:10:52 Re: JDBC error in 7.0.3