Java 8 SQLWarning - 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 SQLWarning class.

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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
    /** 
     * Test method for {@link net.sourceforge.squirrel_sql.fw.util.DefaultExceptionFormatter#format(java.lang.Throwable)}. 
     */     
    @Test 
    public void testDefaultFormatForSQLWarning() {  
        SQLWarning ex = new SQLWarning("low on memory", "WarningState", 1000);
        SQLExecutionException ee = new SQLExecutionException(ex, "postError");
        Assert.assertTrue(formatterUnderTest.formatsException(ex));
        Assert.assertTrue(formatterUnderTest.formatsException(ee));
         
        StringBuilder expectedMessage = 
            new StringBuilder("Warning:   low on memory\n"); 
        expectedMessage.append("SQLState:  WarningState\n");
        expectedMessage.append("ErrorCode: 1000\n");
        expectedMessage.append("postError");
         
        String formattedException = formatterUnderTest.format(ee);
        Assert.assertEquals(expectedMessage.toString(), formattedException);        
    } 
     
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getMessage, getErrorCode, getSQLState
	 * Basic support for {@link WarningHandler} implementations which log 
	 */ 
	public static abstract class WarningHandlerLoggingSupport implements WarningHandler { 
		public final void handleWarning(SQLWarning warning) {
			StringBuffer buf = new StringBuffer(30)
					.append( "SQL Warning Code: ").append( warning.getErrorCode() )
					.append( ", SQLState: ").append( warning.getSQLState() );
			logWarning( buf.toString(), warning.getMessage() );
		} 
 
		/** 
		 * Delegate to log common details of a {@link SQLWarning warning} 
		 * 
		 * @param description A description of the warning 
		 * @param message The warning message 
		 */ 
		protected abstract void logWarning(String description, String message);
	} 
 
	public static class StandardWarningHandler extends WarningHandlerLoggingSupport { 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getSQLState, getNextWarning
        cs_s_u = prepareCall("values cast (? as Integer)",
                ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
 
        // We should have gotten 1 warning 
        warning = conn.getWarnings();
        assertNotNull(warning);
        if (!isDerbyNetClient)
            assertEquals("01J02", warning.getSQLState());
        else 
            assertEquals("01J10", warning.getSQLState());
 
        JDBC.assertNoWarnings(warning.getNextWarning());
        conn.clearWarnings();
        cs_s_u.close();
 
        cs_i_r = prepareCall("values cast (? as Integer)",
                ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
 
        // We should have gotten 0 warnings 
        JDBC.assertNoWarnings(conn.getWarnings());
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getMessage, getErrorCode, getSQLState
    /** 
     * Basic support for {@link WarningHandler} implementations which log 
     */ 
    public static abstract class WarningHandlerLoggingSupport implements WarningHandler {
        public final void handleWarning( SQLWarning warning ) {
            StringBuffer buf = new StringBuffer(30).append("SQL Warning Code: ").append(warning.getErrorCode()).append(", SQLState: ").append(warning.getSQLState());
            logWarning(buf.toString(), warning.getMessage());
        } 
 
        /** 
         * Delegate to log common details of a {@link SQLWarning warning} 
         * 
         * @param description A description of the warning 
         * @param message The warning message 
         */ 
        protected abstract void logWarning( String description,
                                            String message );
    } 
 
    public static class StandardWarningHandler extends WarningHandlerLoggingSupport {
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setNextWarning
     *  
     * @param warning 
     *            Warning 
     */ 
    protected void setWarning(SQLWarning warning) {
        LOGGER.warn("SQL Warning was issued", warning);
        if (this.warnings == null) {
            this.warnings = warning;
        } else { 
            // Chain with existing warnings 
            warning.setNextWarning(this.warnings);
            this.warnings = warning;
        } 
    } 
 
    /** 
     * Helper method that derived classes may use to set warnings 
     *  
     * @param warning 
     *            Warning 

5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:initCause
 
import java.sql.SQLWarning;
 
public class _SQLWarning { 
	public static SQLWarning createNewInstance(Throwable t){
		SQLWarning sql = new SQLWarning();
		sql.initCause(t);
		return sql;
	} 
} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getMessage
        s.executeUpdate("create index i2_a on t2(i)");
 
        // Expect WARNING to also be English. Index is a duplicate 
        s.executeUpdate("create index i2_b on t2(i)");
        SQLWarning sqlw = s.getWarnings();
        assertSQLState("01504", sqlw);
        assertTrue("Expected English warning",  
                sqlw.getMessage().indexOf("duplicate") != -1);
         
        s.close();
        locConn.close();
    } 
         
    /** 
     * Test valid message resolution for German Locale. 
     * converted from i18n/messageLocale.sql 
     * 
     * This test case must run in a decorator that sets the default locale 
     * to Locale.GERMANY. 
     */ 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getMessage
See Code Examples for Java 8 SQLWarning Methods: