catch SQLException, error code for Foeign key violation,

Started by surabhi.ahujaalmost 20 years ago4 messagesgeneral
Jump to latest
#1surabhi.ahuja
surabhi.ahuja@iiitb.ac.in

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

#2Kris Jurka
books@ejurka.com
In reply to: surabhi.ahuja (#1)
Re: catch SQLException, error code for Foeign key violation,

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

#3surabhi.ahuja
surabhi.ahuja@iiitb.ac.in
In reply to: Kris Jurka (#2)
Re: catch SQLException, error code for Foeign key violation,

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

#4Kris Jurka
books@ejurka.com
In reply to: surabhi.ahuja (#3)
Re: catch SQLException, error code for Foeign key violation,

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