From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Matti Aarnio <matti.aarnio@methics.fi>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key
Date: Mon, 11 Feb 2013 19:52:57 +0200
Message-ID: <51192FF9.3090504@vmware.com> (raw)
In-Reply-To: <51190F86.9090102@methics.fi>
References: <E1U4GzT-0005Q0-9a@wrigleys.postgresql.org>
<5118DFDB.4080103@vmware.com>
<51190F86.9090102@methics.fi>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 11.02.2013 17:34, Matti Aarnio wrote:
> } catch (SQLException e) {
> int code = e.getErrorCode();
> if (code == 20000 // Derby
> || code == 23505) {// PostgreSQL, Oracle, ...
> System.out.println("Expected SQL duplicate insert indication
> status code: "+code)
> } else {
> System.out.println("Insert into example at "+this.jdbcUrl+
> " resulted unexpected SQL Exception code: "+
> code + " " + e.getMessage());
> }
Hmm, looking at the PSQLException source code, I don't think the driver
has ever set the vendor-specific error code that getErrorCode() returns.
I tested the snippet you posted with server 8,4 and 9.2, and with jdbc
driver 8.4 and 8.2, and saw no difference; getErrorCode() always returned 0.
You should be using getSQLState() instead. The "23505" sqlstate is
defined by the SQL standard, so if the other DBMS' you're supporting
follow the spec on that, you won't even need any vendor-specific code there.
- Heikki
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: hlinnakangas@vmware.com, matti.aarnio@methics.fi
Subject: Re: BUG #7865: Unexpected error code on insert of duplicate to composite primary key
In-Reply-To: <51192FF9.3090504@vmware.com>
References: <E1U4GzT-0005Q0-9a@wrigleys.postgresql.org> <5118DFDB.4080103@vmware.com> <51190F86.9090102@methics.fi> <51192FF9.3090504@vmware.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox