本文整理汇总了Java中java.sql.BatchUpdateException.getNextException方法的典型用法代码示例。如果您正苦于以下问题:Java BatchUpdateException.getNextException方法的具体用法?Java BatchUpdateException.getNextException怎么用?Java BatchUpdateException.getNextException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.BatchUpdateException
的用法示例。
在下文中一共展示了BatchUpdateException.getNextException方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tratarHibernatePostgreSQL
import java.sql.BatchUpdateException; //导入方法依赖的package包/类
@ExceptionHandler
public void tratarHibernatePostgreSQL(RollbackException e) {
PersistenceException persistenceException = (PersistenceException) e
.getCause();
/*
* Desde aquí ya no es estándar JEE6, estas son clases específicas de
* Hibernate y PostgreSQL dependiendo del proveedor JPA y del motor que
* se utilice esto habrá que adaptar
*/
ConstraintViolationException constraintViolationException = (ConstraintViolationException) persistenceException
.getCause();
BatchUpdateException batchUpdateException = (BatchUpdateException) constraintViolationException
.getCause();
Exception psqlException = batchUpdateException.getNextException();
String msg = psqlException.getLocalizedMessage();
logger.error("Error al realizar el update: " + msg);
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));
}
示例2: insert
import java.sql.BatchUpdateException; //导入方法依赖的package包/类
public void insert() throws SQLException {
try {
statement.executeBatch();
}
catch (BatchUpdateException e) {
throw e.getNextException();
}
finally {
statement.close();
}
}
示例3: getUnderlyingSQLException
import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
* This method will take care of finding the real underlying exception. When a jdbc or hibernate
* exception occurs then the whole stack trace is not available in the log because the exception
* does not return the underlying exception using the {@link Throwable#getCause()} but using the
* {@link SQLException#getNextException()}.
*
* @param throwable
* the throwable to analyze
* @return the underlying sql exception or the original throwable if none found
*/
public static Throwable getUnderlyingSQLException(Throwable throwable) {
if (throwable instanceof BatchUpdateException
&& ((BatchUpdateException) throwable).getNextException() != null) {
return ((BatchUpdateException) throwable).getNextException();
}
if (throwable.getCause() instanceof BatchUpdateException
&& ((BatchUpdateException) throwable.getCause()).getNextException() != null) {
final BatchUpdateException bue = (BatchUpdateException) throwable.getCause();
return bue.getNextException();
}
if (throwable.getCause() instanceof org.hibernate.exception.GenericJDBCException
&& ((org.hibernate.exception.GenericJDBCException) throwable.getCause()).getSQLException()
.getNextException() != null) {
final org.hibernate.exception.GenericJDBCException gjdbce = (org.hibernate.exception.GenericJDBCException) throwable
.getCause();
return gjdbce.getSQLException().getNextException();
}
if (throwable.getCause() instanceof org.hibernate.exception.ConstraintViolationException
&& ((org.hibernate.exception.ConstraintViolationException) throwable.getCause())
.getSQLException().getNextException() != null) {
final org.hibernate.exception.ConstraintViolationException cve = (org.hibernate.exception.ConstraintViolationException) throwable
.getCause();
return cve.getSQLException().getNextException();
}
return throwable;
}
示例4: hibernateData
import java.sql.BatchUpdateException; //导入方法依赖的package包/类
/**
* Hibernate data.
*
* @param article
* the article
* @param session
* the session
* @return true, if successful
*/
public synchronized boolean hibernateData(final NewsArticle article, final Session session) {
Transaction tx = null;
HibernateHelper.logger.debug("hibernateData: " + article.getArticleId());
final Location location = null;
final String gender = null;
try {
tx = session.beginTransaction();
tx.begin();
final UsenetUser poster = this.createUsenetUser(article, session, location, gender);
final Message message = this.createMessage(article, null, poster);
this.storeNewsgroups(article.getNewsgroupsList(), message, session);
tx.commit();
}
catch (Exception e) {
if (e instanceof GenericJDBCException) {
e = (Exception) e.getCause();
}
if (e instanceof BatchUpdateException) {
final BatchUpdateException buex = (BatchUpdateException) e;
System.err.println("Contents of BatchUpdateException:");
System.err.println(" Update counts: ");
final int[] updateCounts = buex.getUpdateCounts();
for (int i = 0; i < updateCounts.length; i++) {
System.err.println(" Statement " + i + ":" + updateCounts[i]);
}
System.err.println(" Message: " + buex.getMessage());
System.err.println(" SQLSTATE: " + buex.getSQLState());
System.err.println(" Error code: " + buex.getErrorCode());
System.err.println(" Article: " + article);
SQLException ex = buex.getNextException();
while (ex != null) {
System.err.println("SQL exception:");
System.err.println(" Message: " + ex.getMessage());
System.err.println(" SQLSTATE: " + ex.getSQLState());
System.err.println(" Error code: " + ex.getErrorCode());
System.err.println(" Error code: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
HibernateHelper.logger.error("Failed to store message", e);
e.printStackTrace();
if (tx != null) {
try {
tx.rollback();
}
catch (final HibernateException e1) {
e1.printStackTrace();
return false;
}
}
}
return true;
}