X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 067EF329E49 for ; Fri, 10 Sep 2004 16:49:16 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19009-07 for ; Fri, 10 Sep 2004 15:49:10 +0000 (GMT) Received: from main.gmane.org (main.gmane.org [80.91.224.249]) by svr1.postgresql.org (Postfix) with ESMTP id ED431329DAE for ; Fri, 10 Sep 2004 16:49:08 +0100 (BST) Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1C5ne6-0005XH-00 for ; Fri, 10 Sep 2004 17:49:06 +0200 Received: from c-24-0-240-136.client.comcast.net ([24.0.240.136]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 10 Sep 2004 17:49:06 +0200 Received: from i.pilcher by c-24-0-240-136.client.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 10 Sep 2004 17:49:06 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Ian Pilcher Subject: Foreign key constraint & getErrorCode Date: Fri, 10 Sep 2004 10:49:02 -0500 Lines: 53 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: c-24-0-240-136.client.comcast.net User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040803 X-Accept-Language: en-us, en X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/30 X-Sequence-Number: 10920 I'm using PostgreSQL 7.4.2 on Fedora Core 2 (included RPMS). When a foreign key constraint fails during an insert, SQLException.getErrorCode is returning zero. Here is a code snippet to demonstrate the problem: import java.io.*; import java.sql.*; class ForeignKey { public static void main(String [] args) throws Exception { Class.forName("org.postgresql.Driver"); Connection db = DriverManager.getConnection(args[0], args[1], args[2]); Statement st = db.createStatement(); st.execute("CREATE TABLE table1 (id INT PRIMARY KEY)"); st.execute("CREATE TABLE table2 (id INT PRIMARY KEY, " + "fk INT NOT NULL REFERENCES " + "table1)"); try { st.execute("INSERT INTO table2 (id, fk) VALUES (0, 0)"); } catch (SQLException sqle) { System.err.println(sqle.getErrorCode() + ": " + sqle.getMessage()); } } } And here's what I get when I run it: [pilcher@home temp]$ echo $CLASSPATH .:/usr/share/java/pg74.1jdbc3.jar [pilcher@home temp]$ java ForeignKey jdbc:postgresql:tomcat4 tomcat4 '' 0: ERROR: insert or update on table "table2" violates foreign key constraint "$1" Based on my reading of the PostgreSQL docs, getErrorCode should be returning 23503. Any idea what's going on? Thanks! -- ======================================================================== Ian Pilcher i.pilcher@comcast.net ========================================================================