X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id C33059FB367 for ; Thu, 31 Aug 2006 06:23:10 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 43002-09 for ; Thu, 31 Aug 2006 06:22:57 -0300 (ADT) X-Greylist: delayed 18:43:52.096851 by SQLgrey- Received: from pjetlic.mobart.hr (pjetlic.mobart.hr [80.80.51.10]) by postgresql.org (Postfix) with ESMTP id B37259FB374 for ; Thu, 31 Aug 2006 06:22:57 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by pjetlic.mobart.hr (Postfix) with ESMTP id CE56517A0E for ; Thu, 31 Aug 2006 11:22:55 +0200 (CEST) Received: from pjetlic.mobart.hr ([127.0.0.1]) by localhost (pjetlic [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 12037-01-10 for ; Thu, 31 Aug 2006 11:22:40 +0200 (CEST) Received: from mike.mobart.hr (mike.mobart.hr [192.168.10.94]) (using SSLv3 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by pjetlic.mobart.hr (Postfix) with ESMTP id 5F3E417A27 for ; Thu, 31 Aug 2006 11:22:40 +0200 (CEST) Subject: Re: Catching postgres exceptions - functions returning From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: pgsql-jdbc@postgresql.org In-Reply-To: References: <1156948727.29660.24.camel@localhost.localdomain> Content-Type: text/plain Organization: Mob-Art Date: Thu, 31 Aug 2006 11:22:39 +0200 Message-Id: <1157016159.3326.8.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by OpenSource AV+AS Mail Server X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.614 tagged_above=0 required=5 tests=AWL, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200608/186 X-Sequence-Number: 15713 On Wed, 2006-08-30 at 18:27 +0200, Marc Herbert wrote: > > Also, some of the functions need to return errorcode of some sort. If > > the function is returning SETOF, I can't use OUT parametars. So, I'm > > asking for a recomendation here. > > Maybe you want to use the SQLState > > http://www.postgresql.org/docs/8.1/interactive/errcodes-appendix.html > > http://www.easysoft.com/developer/interfaces/odbc/sqlstate_status_return_codes.html > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcodbc_error_codes.asp > > http://www.opengroup.org/bookstore/catalog/c451.htm (appendix A) > http://www.opengroup.org/bookstore/catalog/c449.htm (appendix B) > Thank you! :) Although I've found out that errcodes-appendix.html from postgresql manual doesn't contain some errors, for instance: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. at org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:204) at org.postgresql.Driver.connect(Driver.java:139) at java.sql.DriverManager.getConnection(DriverManager.java:525) at java.sql.DriverManager.getConnection(DriverManager.java:171) at Example1.main(Example1.java:31) -------------------------- Message: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. SQLState: 08004 ErrorCode: 0 This, 08004 is not listed there. Then, if I throw some 'custom' exception from postgres (using plpgsql RAISE EXCEPTION), I'll get SQLState code P0001 from getSQLState(). If I want to know what realy happened, I need to parse what getMessage() returns. Is there another way? Mario -- Mario Splivalo Mob-Art mario.splivalo@mobart.hr "I can do it quick, I can do it cheap, I can do it well. Pick any two."