Thread: catch SQLException, error code for Foeign key violation,

catch SQLException, error code for Foeign key violation,

From
"surabhi.ahuja"
Date:
i am working with PostgreSQL 8.0.0
 
and the programming lang used is java
 
i have a stored procedure which inserts a row in a table
 
to this stored procedure i pass the values which have to be inserted in that row.
 
now, i execute this query(which is a call to stored procedure)
 
this execute query is in a try block
 
and i catch SQL exception for it.
 
The question is that is from this SQLException can i detect if it is a foreign key violation,
 
i saw there is a method on SQLException,
e.getErrorCode, is ther specific error code for Foreign Key violation,
 
thanks,
regards
Surabhi

Re: catch SQLException, error code for Foeign key violation,

From
Kris Jurka
Date:

On Mon, 17 Apr 2006, surabhi.ahuja wrote:

> The question is that is from this SQLException can i detect if it is a
> foreign key violation,
>

You should check the value of SQLException.getSQLState() against this
table:
http://www.postgresql.org/docs/8.1/static/errcodes-appendix.html

Kris Jurka

Re: catch SQLException, error code for Foeign key violation,

From
"surabhi.ahuja"
Date:
Thanks .
in java i can catch SQL Exception,
 
 what is the way to capture such exception in Cpp,
are there any examples available for this?
 
right now in cpp, i do this
 
rStatus = PQresultStatus(result);
 
but what is the specific error code, how to get that,
 
thanks,
regards
Surabhi

From: Kris Jurka [mailto:books@ejurka.com]
Sent: Tue 4/18/2006 4:43 AM
To: surabhi.ahuja
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] catch SQLException, error code for Foeign key violation,

***********************
Your mail has been scanned by InterScan VirusWall.
***********-***********




On Mon, 17 Apr 2006, surabhi.ahuja wrote:

> The question is that is from this SQLException can i detect if it is a
> foreign key violation,
>

You should check the value of SQLException.getSQLState() against this
table:
http://www.postgresql.org/docs/8.1/static/errcodes-appendix.html

Kris Jurka

Re: catch SQLException, error code for Foeign key violation,

From
Kris Jurka
Date:

On Wed, 19 Apr 2006, surabhi.ahuja wrote:

> what is the way to capture such exception in Cpp,
> are there any examples available for this?
>
> right now in cpp, i do this
>
> rStatus = PQresultStatus(result);
>
> but what is the specific error code, how to get that,
>

See PQresultErrorField

http://www.postgresql.org/docs/8.1/static/libpq-exec.html

Kris Jurka