Java 8 SQLException - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SQLException class.

This code example shows how to use the following methods:getMessage, getErrorCode, getSQLState
	 * @param sql the offending SQL statement 
	 * @param ex the root cause 
	 */ 
	public UncategorizedSQLException(String task, String sql, SQLException ex) {
		super(task + "; uncategorized SQLException for SQL [" + sql + "]; SQL state [" +
				ex.getSQLState() + "]; error code [" + ex.getErrorCode() + "]; " + ex.getMessage(), ex);
		this.sql = sql;
	} 
 
 
	/** 
	 * Return the underlying SQLException. 
	 */ 
	public SQLException getSQLException() {
		return (SQLException) getCause();
	} 
 
	/** 
	 * Return the SQL that led to the problem. 
	 */ 
8
CodeRank
This code example shows how to use the following methods:getClass, getNextException, getSQLState
 * @author Thomas Risberg 
 * @see java.sql.SQLException#getSQLState() 
 * @see SQLErrorCodeSQLExceptionTranslator 
 */ 
public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLExceptionTranslator { 
 
	private static final Set<String> BAD_SQL_GRAMMAR_CODES = new HashSet<String>(8); 
 
	private static final Set<String> DATA_INTEGRITY_VIOLATION_CODES = new HashSet<String>(8); 
 
	private static final Set<String> DATA_ACCESS_RESOURCE_FAILURE_CODES = new HashSet<String>(8); 
 
	private static final Set<String> TRANSIENT_DATA_ACCESS_RESOURCE_CODES = new HashSet<String>(8); 
 
	private static final Set<String> CONCURRENCY_FAILURE_CODES = new HashSet<String>(4); 
 
 
	static { 
		BAD_SQL_GRAMMAR_CODES.add("07");	// Dynamic SQL error 
		BAD_SQL_GRAMMAR_CODES.add("21");	// Cardinality violation 

8
CodeRank
This code example shows how to use the following methods:
 
public class SybaseExceptionSorterTest extends TestCase {
 
    public void test_false() throws Exception { 
        SybaseExceptionSorter sorter = new SybaseExceptionSorter();
        Assert.assertFalse(sorter.isExceptionFatal(new SQLException()));
    } 
     
    public void test_false_2() throws Exception { 
        SybaseExceptionSorter sorter = new SybaseExceptionSorter();
        Assert.assertFalse(sorter.isExceptionFatal(new SQLException("xxx")));
    } 
     
    public void test_true() throws Exception { 
        SybaseExceptionSorter sorter = new SybaseExceptionSorter();
        Assert.assertTrue(sorter.isExceptionFatal(new SQLException("JZ0C0")));
    } 
     
    public void test_true_1() throws Exception { 
        SybaseExceptionSorter sorter = new SybaseExceptionSorter();
7
CodeRank
This code example shows how to use the following methods:printStackTrace
            throw new RuntimeException("naming error creating initial context", e);
        } 
        try { 
            dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException("datasource error getting connection", e);
        } 
 
        return null; 
    } 
 
    public static boolean getClosedByReaperThread() { 
        return closedByReaperThread.get();
    } 
 
    private Object close() {
        String currentThreadName = Thread.currentThread().getName();
        boolean isBackgroundReaperThread =
            TxUtils.isTransactionManagerTimeoutThread(); 
8
CodeRank
This code example shows how to use the following methods:getMessage
      } catch (SQLException e) {
        try { 
          connection.rollback();
        } 
        catch (SQLException ex) {
          LOG.warn(StringUtils.stringifyException(ex));
        } 
        throw new IOException(e.getMessage());
      } finally { 
        try { 
          statement.close();
          connection.close();
        } 
        catch (SQLException ex) {
          throw new IOException(ex.getMessage());
        } 
      } 
    } 
 
    /** {@inheritDoc} */ 
8
CodeRank
This code example shows how to use the following methods:getMessage
 
   public boolean isExceptionFatal(SQLException e)
   { 
      boolean result = false;
 
      String errorText = (e.getMessage()).toUpperCase();
 
      if ((errorText.indexOf("JZ0C0") > -1) || // ERR_CONNECTION_DEAD
            (errorText.indexOf("JZ0C1") > -1)) // ERR_IOE_KILLED_CONNECTION
      { 
         result = true;
      } 
 
      return result;
   } 
} 
7
CodeRank
This code example shows how to use the following methods:getMessage
			if (rs.next())
			{ 
				numRecords = rs.getLong(1);
			} 
		} catch ( SQLException sqlEx) {
		    LOG.error("getNumRecords() error: " + sqlEx.getMessage(), sqlEx);
		} finally { 
			DBHelper.close(rs,stmt,null);
		} 
		return numRecords;
	} 
 
  /** 
   * 
   * @param from : Defines lower bound of srckey  (> from) 
   * @return resultSet: consists of rows sorted in ascending order of srckey 
   * Note that stmt's lifetime is managed by subclass 
   * @throws SQLException 
   */ 
  public ResultSet getRecords(String from) throws SQLException
8
CodeRank
This code example shows how to use the following methods:getSQLState
      setLongParameter(stmt, 1, userID);
      setLongParameter(stmt, 2, itemID);
      log.debug("Executing SQL update: {}", setPreferenceSQL);
      stmt.executeUpdate();
    } catch (SQLException sqle) {
      if (!POSTGRESQL_DUPLICATE_KEY_STATE.equals(sqle.getSQLState())) {
        log.warn("Exception while setting preference", sqle);
        throw new TasteException(sqle);
      } 
    } finally { 
      IOUtils.quietClose(null, stmt, conn);
    } 
  } 
 
} 
7
CodeRank
This code example shows how to use the following methods:getErrorCode
 * @author Thomas Risberg 
 */ 
public class CustomSqlExceptionTranslator implements SQLExceptionTranslator { 
	@Override 
	public DataAccessException translate(String task, String sql, SQLException ex) {
		if (ex.getErrorCode() == 2) {
			return new TransientDataAccessResourceException("Custom", ex);
		} 
		return null; 
	} 
} 
7
CodeRank
This code example shows how to use the following methods:getSQLState
			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 shutdown in-memory Derby database", ex);
			} 
		} 
	} 
 
} 
7
CodeRank

Related Java 8 SQLException Questions & Answers:

See Code Examples for Java 8 SQLException Methods: