List of usage examples for java.sql SQLException getSQLState
public String getSQLState()
SQLException
object. From source file:org.apache.openjpa.jdbc.sql.SolidDBDictionary.java
@Override public boolean isFatalException(int subtype, SQLException ex) { String errorState = ex.getSQLState(); int errorCode = ex.getErrorCode(); if (subtype == StoreException.LOCK && errorCode == 14529 && "HY000".equals(errorState)) return false; return super.isFatalException(subtype, ex); }
From source file:com.hangum.tadpole.rdb.core.editors.objectmain.ObjectEditor.java
/** * mysql ./*from w ww .j a v a 2s. c o m*/ * * @param reqResultDAO * @param reqQuery * @param e */ private void mysqlAfterProcess(RequestResultDAO reqResultDAO, RequestQuery reqQuery) { if (reqResultDAO.getException() == null) return; String strSQLState = ""; int intSQLErrorCode = -1; Throwable cause = reqResultDAO.getException(); ; if (cause instanceof SQLException) { try { SQLException sqlException = (SQLException) cause; strSQLState = sqlException.getSQLState(); intSQLErrorCode = sqlException.getErrorCode(); if (logger.isDebugEnabled()) logger.debug("==========> SQLState : " + strSQLState + "\t SQLErrorCode : " + intSQLErrorCode); } catch (Exception e) { logger.error("SQLException to striing", e); //$NON-NLS-1$ } } if (strSQLState.equals("42000") && intSQLErrorCode == 1304) { //$NON-NLS-1$ String cmd = String.format("DROP %s %s", reqQuery.getSqlDDLType(), reqQuery.getSqlObjectName()); //$NON-NLS-1$ if (MessageDialog.openConfirm(null, Messages.get().Confirm, String.format(Messages.get().ObjectEditor_13, reqQuery.getSqlObjectName()))) { RequestResultDAO reqReResultDAO = new RequestResultDAO(); try { reqReResultDAO = ExecuteDDLCommand.executSQL(userDB, cmd); //$NON-NLS-1$ afterProcess(reqQuery, reqReResultDAO, Messages.get().ObjectEditor_2); reqReResultDAO = ExecuteDDLCommand.executSQL(userDB, reqQuery.getOriginalSql()); //$NON-NLS-1$ afterProcess(reqQuery, reqReResultDAO, Messages.get().ObjectEditor_2); } catch (Exception ee) { afterProcess(reqQuery, reqResultDAO, ""); //$NON-NLS-1$ } } // 1064 ? ?. // } else if(strSQLState.equals("42000") && intSQLErrorCode == 1064) { //$NON-NLS-1$ } }
From source file:gda.jython.scriptcontroller.logging.LoggingScriptController.java
private void closeDatabase() throws SQLException { if (conn != null) { conn.close();//w w w . jav a 2 s.c o m boolean gotSQLExc = false; try { DriverManager.getConnection("jdbc:derby:" + dbName + ";shutdown=true"); } catch (SQLException se) { if (se.getSQLState().equals("XJ015")) { gotSQLExc = true; } } if (!gotSQLExc) { logger.info("LoggingScriptController database for " + messageClassToLog + " objects did not shut down normally"); } else { logger.info("LoggingScriptController database for " + messageClassToLog + " objects shut down normally"); } } }
From source file:jef.database.DbUtils.java
/** * RuntimeException/*from w ww . j a va 2s . c o m*/ * * @param e * @return */ public static PersistenceException toRuntimeException(SQLException e) { String s = e.getSQLState(); if (e instanceof SQLIntegrityConstraintViolationException) { return new EntityExistsException(e); } else if (e instanceof SQLTimeoutException) { return new QueryTimeoutException(s, e); } return new PersistenceException(s, e); }
From source file:com.ironiacorp.persistence.hibernate.HibernateBootstrap.java
/** * Check the exceptions thrown while running the update or create scripts * for the current Hibernate configuration. * //from ww w . j a va2 s . c o m * @param ddl * The SchemaExport or SchemaUpdate used. * @throws IllegalArgumentException * If the argument is not a SchemaExport or SchemaUpdate * instance. */ @SuppressWarnings("unchecked") private List<Exception> handleExceptions(Object ddl) { if (!(ddl instanceof SchemaExport ^ ddl instanceof SchemaUpdate)) { throw new IllegalArgumentException(); } List<Exception> exceptions = null; List<Exception> errors = new LinkedList<Exception>(); if (ddl instanceof SchemaExport) { SchemaExport schema = (SchemaExport) ddl; exceptions = schema.getExceptions(); } else { SchemaUpdate schema = (SchemaUpdate) ddl; exceptions = schema.getExceptions(); } if (!exceptions.isEmpty()) { for (Object o : exceptions) { Exception e = (Exception) o; SQLException sqle = null; String dialect = null; log.debug(e); if (e instanceof SQLException) { sqle = (SQLException) e; log.debug("SQL error code: " + sqle.getErrorCode()); log.debug("SQL state: " + sqle.getSQLState()); // Filter exceptions. dialect = config.getProperty("dialect"); if (dialect.equals("org.hibernate.dialect.MySQLDialect") || dialect.equals("org.hibernate.dialect.MySQLInnoDBDialect") || dialect.equals("org.hibernate.dialect.MySQLMyISAMDialect")) { e = handleMySQLError(sqle); } } if (e != null) { errors.add(e); } } } return errors; }
From source file:org.openadaptor.auxil.connector.jdbc.sybase.JDBCConnection.java
/** * Perform Sybase specific exception handling. * Has bespoke handling for deadlock detection, empty result set and determination * of Exception type to propagate./* w w w. j a va 2s . c o m*/ * @param e - SQLException to check for Sybase specific handling * @param message - String which will be included as part of propagated Exception if necessary. */ public void handleException(SQLException e, String message) { // ignore deadlock, if num retries > 0 if ((SYBASE_DEADLOCK_DETECTED == e.getErrorCode()) && incrementDeadlockCount() > 0) { log.info("Sybase deadlock detected, " + getDeadlockRetriesRemaining() + " retries remaining"); return; } // ignore empty ResultSet // Fix for SC104 - e.sqlState() may return null, so put it as the argument to the equals() instead. if (SYBASE_EMPTY_RESULT_SET.equals(e.getSQLState())) { return; } // decide whether its a ConnectionException or a ProcessingException switch (e.getErrorCode()) { case SYBASE_COMMUNICATION_ERROR: throw new ConnectionException((message != null ? message + ", " : "") + ", SQLException, " + e.getMessage() + ", Error Code = " + e.getErrorCode() + ", State = " + e.getSQLState(), e, this); default: throw new ProcessingException((message != null ? message + ", " : "") + ", SQLException, " + e.getMessage() + ", Error Code = " + e.getErrorCode() + ", State = " + e.getSQLState(), e, this); } }
From source file:org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.java
private void logTranslation(String task, String sql, SQLException sqlEx, boolean custom) { if (logger.isDebugEnabled()) { String intro = custom ? "Custom translation of" : "Translating"; logger.debug(intro + " SQLException with SQL state '" + sqlEx.getSQLState() + "', error code '" + sqlEx.getErrorCode() + "', message [" + sqlEx.getMessage() + "]; SQL was [" + sql + "] for task [" + task + "]"); }/*from w w w. j av a 2 s. c om*/ }
From source file:org.opendaylight.vtn.javaapi.resources.openstack.RoutesResource.java
/** * Handler method for GET operation of Route * //from www . j a va 2s. c o m * @see org.opendaylight.vtn.javaapi.resources.AbstractResource#get(com. * google.gson.JsonObject) */ @Override public int get(JsonObject queryString) { LOG.trace("Start RoutesResource#get()"); int errorCode = UncResultCode.UNC_SERVER_ERROR.getValue(); String generatedRouteId = null; Connection connection = null; try { connection = VtnServiceInitManager.getDbConnectionPoolMap().getConnection(); /* * Check for instances that they exists or not, if not then return * 404 error */ if (checkForNotFoundResources(connection)) { final RestResource restResource = new RestResource(); errorCode = getStaticRoutes(restResource); if (errorCode == UncCommonEnum.UncResultCode.UNC_SUCCESS.getValue()) { LOG.info("static-route retrieval is successful at UNC."); final JsonObject response = StaticRouteResourceGenerator .convertListResponseBody(restResource.getInfo()); setInfo(response); } else { LOG.error("static-route retrieval is failed at UNC."); } checkForSpecificErrors(restResource.getInfo()); } else { LOG.error("Resource not found error."); } /* * set response, if it is not set during processing for create * tenant */ if (errorCode != UncResultCode.UNC_SUCCESS.getValue()) { if (getInfo() == null) { createErrorInfo(UncResultCode.UNC_INTERNAL_SERVER_ERROR.getValue()); } } } catch (final SQLException exception) { LOG.error(exception, "Internal server error : " + exception); errorCode = UncResultCode.UNC_SERVER_ERROR.getValue(); if (exception.getSQLState().equalsIgnoreCase(VtnServiceOpenStackConsts.CONFLICT_SQL_STATE)) { LOG.error("Conflict found during creation of resource"); createErrorInfo(UncResultCode.UNC_CONFLICT_FOUND.getValue(), getCutomErrorMessage(UncResultCode.UNC_CONFLICT_FOUND.getMessage(), VtnServiceOpenStackConsts.ROUTE_ID, generatedRouteId)); } else { createErrorInfo(UncResultCode.UNC_INTERNAL_SERVER_ERROR.getValue()); } } finally { if (connection != null) { LOG.info("Free connection..."); VtnServiceInitManager.getDbConnectionPoolMap().freeConnection(connection); } } LOG.trace("Complete RoutesResource#get()"); return errorCode; }
From source file:com.splicemachine.derby.impl.load.HBaseBulkLoadIT.java
@Test public void sql8InvalidMergeJoin() throws Exception { if (notSupported) return;/*from w w w. ja v a2s . c o m*/ try { executeQuery(getContent("8-invalid-merge.sql"), "", true); } catch (SQLException e) { // Error expected due to invalid MERGE join: // ERROR 42Y69: No valid execution plan was found for this statement. assertEquals("42Y69", e.getSQLState()); } }
From source file:org.globus.workspace.testing.NimbusTestBase.java
private void shutdownDB() throws Exception { logger.info("Shutting down DB.."); BasicDataSource ds = (BasicDataSource) applicationContext.getBean(DATA_SOURCE_BEAN_NAME); ds.addConnectionProperty("shutdown", "true"); for (int i = 0; i < 1000; i++) { try {//from ww w. ja v a2 s . co m ds.getConnection(); Thread.sleep(10); } catch (SQLException e) { if (e.getSQLState().equals("08006") || e.getSQLState().equals("XJ004")) { logger.info("DB succesfully shutdown. ('" + e.getSQLState() + "')"); return; } else { logger.info("DB not shutdown yet ('" + e.getSQLState() + "')"); } } } throw new Exception("Could not shutdown DB!"); }