SQLException getSQLState - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SQLException getSQLState method.

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:getCause, getMessage, getStackTrace, getErrorCode, getSQLState
	 * @param sqle 
	 * @param sql 
	 * @param dc 
	 */ 
	private DatabaseException(String message, String detail, SQLException sqle, SQL sql,DatasourceConnection dc) {
		super(sqle.getCause() instanceof SQLException?message:"","database");
		 
		set(sql);
		set(sqle,detail);
		set(sqle);
		set(dc);
	} 
	 
	private void set(SQL sql) {
		this.sql=sql;
		if(sql!=null) {
			setAdditional(KeyConstants._SQL,sql.toString());
		} 
	} 
 

7
CodeRank
This code example shows how to use the following methods:getMessage, getErrorCode, getSQLState, getNextWarning
    private SQLWarning getFilteredWarnings(SQLWarning warning) {
        if (warning == null) {
            return null; 
        } 
        else { 
            SQLWarning nextWarning = warning.getNextWarning();
 
            if (ROUND_OR_TRUNCATE_WARNING_MESSAGE.equals(warning.getMessage())) {
                return getFilteredWarnings(nextWarning);
            } 
            else { 
                SQLWarning newWarning = new SQLWarning(warning.getMessage(),
                                                       warning.getSQLState(),
                                                       warning.getErrorCode());
                if (nextWarning != null) {
                    newWarning.setNextWarning(getFilteredWarnings(nextWarning));
                } 
                return newWarning;
            } 
        } 
6
CodeRank
This code example shows how to use the following methods:getMessage, getErrorCode, getSQLState
    private static String constructSQLErrorMessage(SQLExceptionCode code, Throwable e, String message) {
        return constructSQLErrorMessage(code.getErrorCode(), code.getSQLState(), code.getMessage() + " " + e.getMessage() + " " + message);
    } 
 
    private static String constructSQLErrorMessage(SQLException e, String message) {
        return constructSQLErrorMessage(e.getErrorCode(), e.getSQLState(), e.getMessage() + " " + message);
    } 
 
    private static String constructSQLErrorMessage(int errorCode, String SQLState, String message) {
        return String.format(FORMAT, errorCode, SQLState, message);
    } 
 
    public static SQLException parseServerException(Throwable t) {
        SQLException e = parseServerExceptionOrNull(t);
        if (e != null) {
            return e;
        } 
        return new PhoenixIOException(t);
    } 
     
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
This code example shows how to use the following methods:getMessage, getErrorCode, getSQLState, getNextWarning
    private SQLWarning getFilteredWarnings(SQLWarning warning) {
        if (warning == null) {
            return null; 
        } 
        else { 
            SQLWarning nextWarning = warning.getNextWarning();
 
            if (ROUND_OR_TRUNCATE_WARNING_MESSAGE.equals(warning.getMessage())) {
                return getFilteredWarnings(nextWarning);
            } 
            else { 
                SQLWarning newWarning = new SQLWarning(warning.getMessage(),
                                                       warning.getSQLState(),
                                                       warning.getErrorCode());
                if (nextWarning != null) {
                    newWarning.setNextWarning(getFilteredWarnings(nextWarning));
                } 
                return newWarning;
            } 
        } 
6
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:getMessage, getSQLState
            pstmt.setInt(1, eit.getEmployeeId());
            pstmt.execute();
            dbConn.commit();
        } catch (SQLException e) {
            BasicFault bf = new BasicFault();
            String errorMsg = "SQLState: " + e.getSQLState() + "; Message: "
                    + e.getMessage();
            bf.setErrorDetails(errorMsg);
            throw new DataProcessingFault( 
                    "Error while trying to delete employee record", bf);
        } 
        return null; 
    } 
 
    static XMLGregorianCalendar sqlDateToXMLCal(java.sql.Date sqlDate) {
        java.util.Date jDate = new java.util.Date(sqlDate.getTime());
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(jDate);
        return df.newXMLGregorianCalendar(calendar);
    } 
6
CodeRank
This code example shows how to use the following methods:getSQLState
 
      log.debug("Executing SQL update: {}", setPreferenceSQL);
      try { 
        stmt1.executeUpdate();
      } catch (SQLException sqle) {
        if (!POSTGRESQL_DUPLICATE_KEY_STATE.equals(sqle.getSQLState())) {
          throw sqle;
        } 
      } 
 
      // Continue with update; just found the key already exists 
 
      stmt2 = conn.prepareStatement(getUpdatePreferenceSQL());
      stmt2.setDouble(1, value);
      setLongParameter(stmt2, 2, userID);
      setLongParameter(stmt2, 3, itemID);
 
      log.debug("Executing SQL update: {}", getUpdatePreferenceSQL()); 
      stmt2.executeUpdate();
 

7
CodeRank
getSQLState Method Overview
Retrieves the SQLState for this SQLException object.
See Code Examples for other Java 8 SQLException Methods: