本文整理汇总了Java中org.h2.jdbc.JdbcSQLException.getErrorCode方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcSQLException.getErrorCode方法的具体用法?Java JdbcSQLException.getErrorCode怎么用?Java JdbcSQLException.getErrorCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.jdbc.JdbcSQLException
的用法示例。
在下文中一共展示了JdbcSQLException.getErrorCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeFile
import org.h2.jdbc.JdbcSQLException; //导入方法依赖的package包/类
private synchronized void writeFile(String s, Throwable t) {
try {
if (checkSize++ >= CHECK_SIZE_EACH_WRITES) {
checkSize = 0;
closeWriter();
if (maxFileSize > 0 && FileUtils.size(fileName) > maxFileSize) {
String old = fileName + ".old";
FileUtils.delete(old);
FileUtils.move(fileName, old);
}
}
if (!openWriter()) {
return;
}
printWriter.println(s);
if (t != null) {
if (levelFile == ERROR && t instanceof JdbcSQLException) {
JdbcSQLException se = (JdbcSQLException) t;
int code = se.getErrorCode();
if (ErrorCode.isCommon(code)) {
printWriter.println(t.toString());
} else {
t.printStackTrace(printWriter);
}
} else {
t.printStackTrace(printWriter);
}
}
printWriter.flush();
if (closed) {
closeWriter();
}
} catch (Exception e) {
logWritingError(e);
}
}
示例2: translateExceptionIfPossible
import org.h2.jdbc.JdbcSQLException; //导入方法依赖的package包/类
/**
* Translates an H2 database error into a Rave application Exception
*
* @param re the RuntimeException to translate to a Rave application exception
* @return a Rave application exception representing the database error
*/
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException re) {
DataAccessException e = null;
// first make sure the root exception is actually an org.h2.jdbc.JdbcSQLException
if (ExceptionUtils.getRootCause(re) instanceof JdbcSQLException) {
JdbcSQLException rootException = (JdbcSQLException)ExceptionUtils.getRootCause(re);
// now translate the H2 specific error codes into Rave's common application Exceptions
// add more error codes to the switch statement that should be specifically trapped
switch(rootException.getErrorCode()) {
case ErrorCode.DUPLICATE_KEY_1: {
e = new DuplicateItemException("DUPLICATE_ITEM", rootException);
break;
}
default: {
e = new TranslatedH2Exception(rootException.getErrorCode(), "ERROR", "Unknown Database Error");
break;
}
}
} else {
// we got a RuntimeException that wasn't an org.h2.jdbc.JdbcSQLException
e = new TranslatedH2Exception(TranslatedH2Exception.UNKNOWN_ERROR_CODE, "ERROR", "Unknown Runtime Exception");
}
return e;
}