Re: PSQLException - How to Identify Type? - Mailing list pgsql-jdbc

From Craig Ringer
Subject Re: PSQLException - How to Identify Type?
Date
Msg-id 48F59719.8040801@postnewspapers.com.au
Whole thread Raw
In response to PSQLException - How to Identify Type?  ("Ryan Daniels" <ryan.daniels@gmail.com>)
List pgsql-jdbc
Ryan Daniels wrote:
>
> Hello,
>
> When I get a PSQLException, how do I identify which type it is? I need
> to be able to distinguish which error occurred.

Have a look at the JDBC documentation, in particular the documentation
for SQLException.

http://java.sun.com/javase/6/docs/api/java/sql/SQLException.html

Note the getErrorCode() and getSQLState() members?

The error code is usually quite sufficient for program flow control and
error handling decisions. See the PostgreSQL error code documentation:

http://www.postgresql.org/docs/current/static/errcodes-appendix.html

Note that you can match error codes by class (the first byte) as well as
by exact error code. As a result, you can easily do things like "Retry
the transaction on all possibly tansient errors" in quite a generic way.


The documentation for PSQLException shows you how to get information
from it, too:

http://jdbc.postgresql.org/development/privateapi/org/postgresql/util/PSQLException.html

it provdes getServerErrorMessage(), which returns about as much as you'd
ever want to know:

http://jdbc.postgresql.org/development/privateapi/org/postgresql/util/ServerErrorMessage.html

--
Craig Ringer

pgsql-jdbc by date:

Previous
From: "Ryan Daniels"
Date:
Subject: PSQLException - How to Identify Type?
Next
From: mark_addleman@bigfoot.com
Date:
Subject: Re: COPY support in JDBC driver?