List of usage examples for java.sql SQLException getNextException
public SQLException getNextException()
SQLException
object by setNextException(SQLException ex). From source file:org.efaps.util.EFapsException.java
/** * If a caused exception is a {@link SQLException}, also all next * exceptions of the {@link SQLException}'s are printed into the stack * trace.//from w w w.j a va 2s . co m * * @param _stream <code>PrintStream</code> to use for output * @see #makeInfo() to get all information about this EFapsException */ @Override public void printStackTrace(final PrintStream _stream) { _stream.append(makeInfo()); super.printStackTrace(_stream); if (getCause() != null && getCause() instanceof SQLException) { SQLException ex = (SQLException) getCause(); ex = ex.getNextException(); while (ex != null) { _stream.append("Next SQL Exception is: "); ex.printStackTrace(_stream); ex = ex.getNextException(); } } }
From source file:org.efaps.util.EFapsException.java
/** * If a caused exception is a {@link SQLException}, also all next * exceptions of the {@link SQLException}'s are printed into the stack * trace.//ww w.ja va 2 s .co m * * @param _writer <code>PrintWriter</code> to use for output * @see #makeInfo() to get all information about this EFapsException */ @Override public void printStackTrace(final PrintWriter _writer) { _writer.append(makeInfo()); if (this.className != null) { _writer.append("Thrown within class ").append(this.className.getName()).append('\n'); } super.printStackTrace(_writer); if (getCause() != null && getCause() instanceof SQLException) { SQLException ex = (SQLException) getCause(); ex = ex.getNextException(); while (ex != null) { _writer.append("Next SQL Exception is: "); ex.printStackTrace(_writer); ex = ex.getNextException(); } } }
From source file:org.wso2.authenticator.jdbc.JDBCAuthenticator.java
/** * Open (if necessary) and return a database connection for use by this * Realm./*from w w w. j a v a 2 s . c om*/ * * @exception SQLException * if a database error occurs */ public Connection open() throws AuthenticatorException, SQLException { if (dbConnection != null) return (dbConnection); if (connectionURL == null) { throw new AuthenticatorException("Connection URL is null"); } if (driver == null) { try { Class clazz = Class.forName(driverName); driver = (Driver) clazz.newInstance(); } catch (Throwable e) { log.debug(e.getMessage(), e); e.printStackTrace(); SQLException exc = new SQLException(); if (exc.getNextException() != null) { Exception nextExecption = exc.getNextException(); log.debug("exceptionOnConnectionOpen", nextExecption); } throw new AuthenticatorException("exceptionOnConnectionOpen", e); } } Properties props = new Properties(); if (connectionUserName != null) props.put("user", connectionUserName); if (connectionPassword != null) props.put("password", connectionPassword); dbConnection = driver.connect(connectionURL, props); dbConnection.setAutoCommit(false); return (dbConnection); }
From source file:nl.b3p.gis.viewer.struts.BaseHibernateAction.java
/** * Een Struts action execute die verwijst naar de standaard action als alles goed verloopt en anders een * alternatieve forward aanroept./*from w w w .j a va2 s . c o m*/ * * @param mapping ActionMapping die gebruikt wordt voor deze forward. * @param form ActionForm die gebruikt wordt voor deze forward. * @param request HttpServletRequest die gebruikt wordt voor deze forward. * @param response HttpServletResponse die gebruikt wordt voor deze forward. * * @return ActionForward met de struts forward waar deze methode naar toe moet verwijzen. * * @throws Exception * */ // <editor-fold defaultstate="" desc="public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception"> public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Session sess = getHibernateSession(); Transaction tx = sess.beginTransaction(); ActionForward forward = null; String msg = null; try { forward = super.execute(mapping, form, request, response); tx.commit(); return forward; } catch (Exception e) { if (tx.isActive()) { tx.rollback(); } log.error("Exception occured, rollback", e); if (e instanceof org.hibernate.JDBCException) { msg = e.getMessage(); SQLException sqle = ((org.hibernate.JDBCException) e).getSQLException(); msg = msg + ": " + sqle; SQLException nextSqlE = sqle.getNextException(); if (nextSqlE != null) { msg = msg + ": " + nextSqlE; } } else if (e instanceof java.sql.SQLException) { msg = e.getMessage(); SQLException nextSqlE = ((java.sql.SQLException) e).getNextException(); if (nextSqlE != null) { msg = msg + ": " + nextSqlE; } } else { msg = e.getMessage(); } addAlternateMessage(mapping, request, null, msg); return getAlternateForward(mapping, request); } }
From source file:nl.b3p.gis.viewer.ViewerCrudAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Session sess = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction tx = sess.getTransaction(); tx.begin();//from w ww . ja v a2s . c o m ActionForward forward = null; String msg = null; try { forward = super.execute(mapping, form, request, response); tx.commit(); return forward; } catch (Exception e) { tx.rollback(); log.error("Exception occured, rollback", e); MessageResources messages = getResources(request); if (e instanceof org.hibernate.JDBCException) { msg = e.toString(); SQLException sqle = ((org.hibernate.JDBCException) e).getSQLException(); msg = msg + ": " + sqle; SQLException nextSqlE = sqle.getNextException(); if (nextSqlE != null) { msg = msg + ": " + nextSqlE; } } else if (e instanceof java.sql.SQLException) { msg = e.toString(); SQLException nextSqlE = ((java.sql.SQLException) e).getNextException(); if (nextSqlE != null) { msg = msg + ": " + nextSqlE; } } else { msg = e.toString(); } addAlternateMessage(mapping, request, null, msg); } // Start tweede sessie om tenminste nog de lijsten op te halen sess = HibernateUtil.getSessionFactory().getCurrentSession(); tx = sess.getTransaction(); tx.begin(); try { prepareMethod((DynaValidatorForm) form, request, LIST, EDIT); //throw new Exception("Lorem Ipsum 2"); tx.commit(); } catch (Exception e) { tx.rollback(); log.error("Exception occured in second session, rollback", e); addAlternateMessage(mapping, request, null, e.toString()); } //addAlternateMessage(mapping, request, null, message); return getAlternateForward(mapping, request); }
From source file:org.apereo.portal.portlet.dao.jpa.SQLNextExceptionLoggerAspect.java
public void logBatchUpdateExceptions(Throwable t) { while (!(t instanceof SQLException)) { t = t.getCause();/*w w w . j a v a 2 s . c om*/ if (t == null) { return; } } SQLException sqle = (SQLException) t; //If the SQLException is the root chain the results of getNextException as initCauses if (sqle.getCause() == null) { SQLException nextException; while ((nextException = sqle.getNextException()) != null) { sqle.initCause(nextException); sqle = nextException; } } //The SQLException already has a cause so log the results of all getNextException calls else { while ((sqle = sqle.getNextException()) != null) { this.logger.error("Logging getNextException for root SQLException: " + t, sqle); } } }
From source file:org.executequery.databaseobjects.impl.AbstractNamedObject.java
protected final void logSQLException(SQLException e) { e.printStackTrace();//from w w w. j a v a2 s . c o m SQLException nextException = e; while ((nextException = nextException.getNextException()) != null) { nextException.printStackTrace(); } }
From source file:org.nextframework.persistence.exception.PostgreSQLErrorCodeSQLExceptionTranslator.java
@Override protected DataAccessException customTranslate(String task, String sql, SQLException sqlEx) { //TODO ARRUMAR ESSA ALGORITMO (FAZER HIGH COHESION.. LOW COUPLING) //System.out.println(task+" - "+sql); if (sqlEx.getNextException() != null) { sqlEx = sqlEx.getNextException();//tentar buscar a excecao mais especifica }/*from w ww . j a va 2s . c o m*/ String errorMessage = sqlEx.getMessage(); Matcher matcher = pattern.matcher(errorMessage); Matcher matcherIngles = patternIngles.matcher(errorMessage); Matcher matcherNullIngles = patternInglesNull.matcher(errorMessage); Matcher matcherNull = patternNull.matcher(errorMessage); System.out.println(">>> " + errorMessage); if (!matcher.find()) { matcher = matcherIngles; } else { matcher.reset(); } if (matcher.find()) { //exceo de FK //String fk_name = matcher.group(2); String fk_table_name = matcher.group(3).toUpperCase(); String pk_table_name = matcher.group(1).toUpperCase(); String fkTableDisplayName = null; String pkTableDisplayName = null; // try { // DatabaseMetaData metaData = dataSource.getConnection().getMetaData(); // ResultSet importedKeys = metaData.getImportedKeys(null,null, fk_table_name); // // while(importedKeys.next()){ // if(importedKeys.getString("FK_NAME").equals(fk_name)){ // pk_table_name = importedKeys.getString("PKTABLE_NAME"); // if(pk_table_name != null){ // pk_table_name = pk_table_name.toUpperCase(); // } // } // } // } catch (SQLException e) { // //se nao conseguir o metadata .. vazar // log.warn("No foi possvel conseguir o metadata do banco para ler informacoes de FK."); // return null; // } Class<?>[] entities = ClassManagerFactory.getClassManager().getClassesWithAnnotation(Entity.class); pkTableDisplayName = pk_table_name; fkTableDisplayName = fk_table_name; for (Class<?> entityClass : entities) { String tableName = getTableName(entityClass); if (tableName.equals(pk_table_name)) { pkTableDisplayName = BeanDescriptorFactory.forClass(entityClass).getDisplayName(); } if (tableName.equals(fk_table_name)) { fkTableDisplayName = BeanDescriptorFactory.forClass(entityClass).getDisplayName(); } } String mensagem = null; if (sql.toLowerCase().trim().startsWith("delete")) { mensagem = "No foi possvel remover " + pkTableDisplayName + ". Existe(m) registro(s) vinculado(s) em " + fkTableDisplayName + "."; } else if (sql.toLowerCase().trim().startsWith("update")) { mensagem = "No foi possvel atualizar " + fkTableDisplayName + ". A referncia para " + pkTableDisplayName + " invlida."; } else if (sql.toLowerCase().trim().startsWith("insert")) { mensagem = "No foi possvel inserir " + fkTableDisplayName + ". A referncia para " + pkTableDisplayName + " invlida."; } return new ForeignKeyException(mensagem); } else if (matcherNullIngles.find()) { return new ApplicationDatabaseException(errorMessage); } else if (matcherNull.find()) { return new ApplicationDatabaseException(errorMessage); } else { int indexOf = errorMessage.indexOf("APP"); if (indexOf > 0) { errorMessage = errorMessage.substring(indexOf + 3); return new ApplicationDatabaseException(errorMessage); } } return null; }
From source file:org.orbisgis.dbjobs.jobs.ImportFiles.java
@Override protected Object doInBackground() throws Exception { long deb = System.currentTimeMillis(); try (Connection connection = dataManager.getDataSource().getConnection()) { ProgressMonitor filePm = this.getProgressMonitor().startTask(files.size()); boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); for (File file : files) { String ext = FilenameUtils.getExtension(file.getName()); DriverFunction driverFunction = driverFunctionContainer.getImportDriverFromExt(ext, driverType); if (driverFunction != null) { String tableNameTest = TableLocation.capsIdentifier(FileUtils.getNameFromURI(file.toURI()), isH2);/*from w ww. j av a 2 s.com*/ if (tableNameTest == null) { tableNameTest = FileUtils.getNameFromURI(file.toURI()); } String tableName = dataManager .findUniqueTableName(new TableLocation("", schema, tableNameTest).toString(isH2)); driverFunction.importFile(connection, tableName, file, new H2GISProgressMonitor(filePm)); } else { LOGGER.error(I18N.tr("No driver found for {0} extension", ext)); } } } catch (SQLException ex) { LOGGER.error(I18N.tr("Cannot import the file.\nCause : {0}", ex.getMessage()), ex); // Print additional information while ((ex = ex.getNextException()) != null) { LOGGER.error(ex.getLocalizedMessage()); } } catch (IOException ex) { LOGGER.error(I18N.tr("Cannot import the file.\nCause : {0}", ex.getMessage()), ex); } LOGGER.info(I18N.tr("Importation done in {0} sec", (System.currentTimeMillis() - deb) / 1000d)); dbView.onDatabaseUpdate(DatabaseView.DB_ENTITY.SCHEMA.name(), "PUBLIC"); return null; }
From source file:com.gs.obevo.db.impl.core.jdbc.JdbcHelper.java
private void logSqlBatchException(SQLException e, int level) { LOG.error("Batch stack trace level #{}", level); LOG.error("", e); if (e != null) { this.logSqlBatchException(e.getNextException(), level + 1); }// w ww.jav a 2 s . c o m }