Re: Information in SQLException
- From: IchBin <weconsul@xxxxxxx>
- Date: Thu, 24 Nov 2005 12:12:59 -0500
Bjorn Abelli wrote:
IchBin wrote:Bjorn Abelli wrote:"hombre" wrote...
How do I know that the SLQException is thrown because of the duplicate customerID and not because of a duplicate primary key or any other sort of SQL error. Do I have to parse the detailMessage-String ?
[on getErrorCode]
- 1022 for duplicates that is because of the primary key - 1062 for duplicates that *isn't* the primary key
Try some like this.. Could use either state or code checks
try { .. .. int updatedRowCount = sqlStatement.executeUpdate(sqlCmd);
} catch (SQLException ex) { // handle any errors
if (ex.getSQLState()) == 23000 | ex.getErrorCode() == 1022){ dialogToDisplayYourMessage(); }Sorry.. if (ex.getSQLState()) == 23000 && ex.getErrorCode() == 1022){
SQLState 23000 also catches what the OP didn't want to catch, duplicate primary keys.
ErrorCode 1022 definitely catches what the OP didn't want to catch, duplicate primary keys.
It should suffice with:
if (ex.getErrorCode() == 1062)
But that will still only work with MySQL, and if the table doesn't have any more unique fields than the primary key and CustomerID.
// Bjorn A
Sorry Bjorn, I need to slow down before I reply..
--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-) .
- Follow-Ups:
- Re: Information in SQLException
- From: hombre
- Re: Information in SQLException
- References:
- Information in SQLException
- From: hombre
- Re: Information in SQLException
- From: Bjorn Abelli
- Re: Information in SQLException
- From: IchBin
- Re: Information in SQLException
- From: IchBin
- Re: Information in SQLException
- From: Bjorn Abelli
- Information in SQLException
- Prev by Date: Re: Unable to update record in java
- Next by Date: DBModelled Storage in JAVA
- Previous by thread: Re: Information in SQLException
- Next by thread: Re: Information in SQLException
- Index(es):