Re: sending a block through jdbc

From: Kris Jurka <books(at)ejurka(dot)com>
To: Maxime Lévesque <maxime(dot)levesque(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: sending a block through jdbc
Date: 2010-05-01 14:02:55
Message-ID: alpine.BSO.2.00.1005010959380.24884@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Fri, 30 Apr 2010, Maxime L?vesque wrote:

> I want to drop a constraint if it exists, and not get an error if it
> doesn't exist, ideally I'd get a jdbc error code, and silence the
> 'consrtaint does not exist' exception, but since postgress doesn't send
> error codes to jdbc, I'd like to put the statement in a block and
> silence the exception like this

PG sets SQLState in the SQLException since it is standardized and not
error code which is vendor specific.

> sb.append("begin \n");
> sb.append("alter table " + foreingKeyTable.name + " drop
> constraint " + fkName + ";\n");
> sb.append("exception when true then \n");
> sb.append("end;");
>
> It seems that this is either unsupported or I have bad syntax....

PG will only support anonymous blocks in the upcoming 9.0 release, and
then with a different syntax.

http://developer.postgresql.org/pgdocs/postgres/sql-do.html

Kris Jurka

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2010-05-01 14:41:50 Re: Very Dangerous bug in XA connection pooling and SL EJBs with jboss-4.2.3 & latest postgresql-8.4-701.jdbc3.jar
Previous Message Maxime Lévesque 2010-05-01 03:20:20 sending a block through jdbc