Обсуждение: ErrorCodes suddenly stopped working? [possibly my programming error]

Поиск
Список
Период
Сортировка

ErrorCodes suddenly stopped working? [possibly my programming error]

От
Assad Jarrahian
Дата:
Postgres 8.1.4 beta.
I may have modified something, but I dont think I did.

code:

try{
            registerUser.setString(1,client.getName());
            registerUser.setString(2,client.getPassword());
            registerUser.executeUpdate();
        }
        catch(SQLException ex) {
            if (ex.getErrorCode()== 23505)
                throw new ProximityDBException("UserName Already Exists",
ProximityDBException.ERROR_AUTHENTICATION_FAILED);
            else
                System.out.println("ERROR CODE FROM SQLException " + ex.getErrorCode());
                throw new ProximityDBException(ex.getMessage(), ex.getErrorCode());
        }
    }

before it would throw getErrorCode() as 23505 with a duplicate
username. Now all it throws is 0 (for other prepared statements as
well).

I get this from SQLException
ERROR: duplicate key violates unique constraint "table_user" 0

Is there a way to check what went wrong (or what I did wrong)? Your
input is appreciated. Thanks.

-assad

Re: ErrorCodes suddenly stopped working? [possibly my

От
Kris Jurka
Дата:

On Sun, 13 Nov 2005, Assad Jarrahian wrote:

>         catch(SQLException ex) {
>             if (ex.getErrorCode()== 23505)
>
> before it would throw getErrorCode() as 23505 with a duplicate
> username. Now all it throws is 0 (for other prepared statements as
> well).

Postgresql has never used error codes, these are vendor specific numbers
and I'm guessing you ran this code against some other database.
Postgresql reports SQL State values.  Use SQLException.getSQLState()
instead.

Kris Jurka