Added isDuplicateRowException() for determining whether or not an

exception was caused by inserting a duplicate row into a table that
disallows such actions.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@63 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-03-01 22:59:51 +00:00
parent 89849663c4
commit bdbb9ad427
@@ -1,5 +1,5 @@
// //
// $Id: MySQLRepository.java,v 1.1 2001/02/13 00:25:14 mdb Exp $ // $Id: MySQLRepository.java,v 1.2 2001/03/01 22:59:51 mdb Exp $
package com.samskivert.jdbc; package com.samskivert.jdbc;
@@ -38,4 +38,18 @@ public abstract class MySQLRepository extends Repository
return -1; return -1;
} }
} }
/**
* Determines whether or not the supplied SQL exception originated
* from a duplicate row error.
*
* @return true if the exception was thrown because a duplicate row
* was inserted into a table that does not allow such things, false if
* the exception is not related to duplicate rows.
*/
protected boolean isDuplicateRowException (SQLException sqe)
{
String msg = sqe.getMessage();
return (msg != null && msg.indexOf("Duplicate entry") != -1);
}
} }