🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8629

Re: SQLException - determining cause?

#8629
From: Torsten Welches
Date: Mon, 12 Mar 2001 18:52
28 lines
1852 bytes
AJ,

SQLException.getSQLState() returns a "SQLstate string, which follows the
XOPEN SQLstate conventions".
SQLException.getErrorCode() returns "the vendor-specific exception code".

If it's only about the update/insert problem I suggest you do a simple
"select count(*)" to check if the row is already there or not.

Torsten

AJ schrieb in Nachricht <3aad0fc8$1_2@dnews>...
>After a call to PreparedStatement.executeUpdate to do an insert, I get an
>SQLException.  How do I determine if this is due to a duplicate key, i.e.
>the row is already there?  Are there sub-types to SQLExceptions?  Do I have
>to look at XOPEN SQL states?  I need this to be database independent, so
>vendor-specific error codes will not help.
>
>Bottom line:  if the row is duplicate, I want to update instead of insert.
>I suppose I could just try to update if the insert fails, but I'd like to
be
>sure that I'm only doing so in the specific case of a duplicate row error.
>
>Thanks,
>AJ
>
>
>
Technical Details
Message-ID: <3aad1bf4_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!newspeer1.nac.net!colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!dnews!195.14.235.213
References: <3aad0fc8$1_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,f26c03738229183f
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-12 11:16:05 PST
From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de>
Newsgroups: borland.public.jbuilder.java.language
References: <3aad0fc8$1_2@dnews>
Subject: Re: SQLException - determining cause?
Date: Mon, 12 Mar 2001 19:52:49 +0100
Lines: 30
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
NNTP-Posting-Host: 195.14.235.213
Message-ID: <3aad1bf4_1@dnews>
X-Trace: 12 Mar 2001 10:56:52 -0800, 195.14.235.213
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!newspeer1.nac.net!colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!dnews!195.14.235.213