4

When writing java code that uses an Oracle database, one can always catch SQLException an read an specific Oracle error with e.getErrorCode(). For example, error 28001 means expired password, 28000 is blocked account, 1017 is wrong user/passsword, etc.

That way I can manage different errors the appropiate way.

But with PostgreSQL databases e.getErrorCode() always returns 0, even when catching Postgres-specific PSQLException.

The Question

  • Is there a way that I don't know of to get an specific error code for a Postgres database exception in Java other than trying to parse the error message (which by the way could be in any localized language)?
2

1 Answer 1

2

Have you tried looking at getSqlState() instead? See also: http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html

Sign up to request clarification or add additional context in comments.

1 Comment

Every failed connection attempt returns "08001" regardless of the reason (bad password, bad IP, bad port, bad user, bad database name, no network conecction), everything returns "08001".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.