List of usage examples for java.sql SQLException getSQLState
public String getSQLState()
SQLException
object. From source file:TaskManager.java
public static String readException(SQLException sqlX) { StringBuffer msg = new StringBuffer(1024); SQLException nextX;//from ww w . j a v a2s. c o m int exceptionNumber = 0; do { ++exceptionNumber; msg.append("Exception " + exceptionNumber + ": \n"); msg.append(" Message: " + sqlX.getMessage() + "\n"); msg.append(" State : " + sqlX.getSQLState() + "\n"); msg.append(" Code : " + sqlX.getErrorCode() + "\n"); } while ((nextX = sqlX.getNextException()) != null); return (msg.toString()); }
From source file:com.xqdev.sql.MLSQL.java
private static void addExceptions(Element meta, SQLException e) { if (e == null) return;// www . j a v a2s . com Namespace sql = meta.getNamespace(); Element exceptions = new Element("exceptions", sql); meta.addContent(exceptions); do { exceptions.addContent(new Element("exception", sql).setAttribute("type", e.getClass().getName()) .addContent(new Element("reason", sql).setText(e.getMessage())) .addContent(new Element("sql-state", sql).setText(e.getSQLState())) .addContent(new Element("vendor-code", sql).setText("" + e.getErrorCode()))); e = e.getNextException(); } while (e != null); }
From source file:de.micromata.genome.util.jdbc.LauncherDataSource.java
@Override public Connection getConnection() throws SQLException { try {/*w ww.j a v a 2 s . c o m*/ Connection con = super.getConnection(); return con; } catch (SQLException ex) { if ("XJ004".equals(ex.getSQLState()) == true) { String orgurl = getUrl(); try { setUrl(getUrl() + ";create=true"); return super.getConnection(); } finally { setUrl(orgurl); } } throw ex; } }
From source file:test.jdbc.datasource.DerbyShutdownBean.java
@Override public void destroy() throws Exception { logger.info("Attempting Derby database shut down on: " + dataSource); if (!isShutdown && dataSource != null && dataSource instanceof EmbeddedDataSource) { EmbeddedDataSource ds = (EmbeddedDataSource) dataSource; try {/*w w w. j a v a 2 s .c om*/ ds.setShutdownDatabase("shutdown"); ds.getConnection(); } catch (SQLException except) { if (except.getSQLState().equals("08006")) { // SQLState derby throws when shutting down the database logger.info("Derby database is now shut down."); isShutdown = true; } else { logger.error("Problem shutting down Derby " + except.getMessage()); } } } }
From source file:org.apache.torque.util.ExceptionMapperImpl.java
@Override public TorqueException toTorqueException(SQLException sqlException) { if (StringUtils.startsWith(sqlException.getSQLState(), "23")) { return new ConstraintViolationException(sqlException); }//from w w w .j av a 2s . c o m if (StringUtils.equals(sqlException.getSQLState(), "40001")) { // mysql, derby, mssql return new DeadlockException(sqlException); } if (StringUtils.equals(sqlException.getSQLState(), "40P01")) { // postgresql return new DeadlockException(sqlException); } if (StringUtils.equals(sqlException.getSQLState(), "61000") && sqlException.getErrorCode() == 60) { // oracle return new DeadlockException(sqlException); } return new TorqueException(sqlException); }
From source file:HelloMySQLJDBC.java
private void displaySQLErrors(SQLException e) { System.out.println("SQLException: " + e.getMessage()); System.out.println("SQLState: " + e.getSQLState()); System.out.println("VendorError: " + e.getErrorCode()); }
From source file:org.apache.sqoop.mapreduce.db.SQLServerConnectionFailureHandler.java
/** * Handle only connection reset or TCP exceptions. */// ww w. j a v a2s . c om public boolean canHandleFailure(Throwable failureCause) { if (!super.canHandleFailure(failureCause)) { return false; } SQLException sqlEx = (SQLException) failureCause; String errStateCode = sqlEx.getSQLState(); boolean canHandle = false; // By default check SQLState code if available if (errStateCode != null) { canHandle = errStateCode == SQLSTATE_CODE_CONNECTION_RESET; } else { errStateCode = "NULL"; // In case SQLState code is not available, check the exception message String errMsg = sqlEx.getMessage(); canHandle = errMsg.matches(CONNECTION_RESET_ERR_REGEX); } if (!canHandle) { LOG.warn("Cannot handle error with SQL State: " + errStateCode); } return canHandle; }
From source file:org.springframework.jdbc.datasource.embedded.DerbyEmbeddedDatabaseConfigurer.java
@Override public void shutdown(DataSource dataSource, String databaseName) { try {/*from www .j a v a 2 s. c o m*/ new EmbeddedDriver().connect(String.format(URL_TEMPLATE, databaseName, "drop=true"), new Properties()); } catch (SQLException ex) { // Error code that indicates successful shutdown if (!"08006".equals(ex.getSQLState())) { LogFactory.getLog(getClass()).warn("Could not shut down embedded Derby database", ex); } } }
From source file:org.seasar.dbflute.helper.jdbc.sqlfile.DfSqlFileRunnerExecute.java
protected StringBuilder buildAdditionalErrorInfo(StringBuilder sb, SQLException e) { sb.append("(SQLState=").append(e.getSQLState()).append(" ErrorCode=").append(e.getErrorCode()).append(")"); return sb;// ww w . j a v a 2 s . c om }
From source file:org.atricore.idbus.idojos.dbidentitystore.DataSourceIdentityStore.java
/** * Opens a new DB Connection, retrieved from the DS. * * @throws SSOIdentityException/*from www. j a va 2 s .c om*/ */ public Connection getDBConnection() throws SSOIdentityException { try { return getDataSource().getConnection(); } catch (SQLException e) { logger.error("[getDBConnection()]:" + e.getErrorCode() + "/" + e.getSQLState() + "]" + e.getMessage()); throw new SSOIdentityException("Exception while getting connection: \n " + e.getMessage()); } }