Search in sources :

Example 11 with SQLWarning

use of java.sql.SQLWarning in project jdk8u_jdk by JetBrains.

the class SQLWarningTests method test14.

/**
     * Validate that the ordering of the returned SQLWarning is correct using
     * traditional while loop
     */
@Test
public void test14() {
    SQLWarning ex = new SQLWarning("Warning 1", t1);
    SQLWarning ex1 = new SQLWarning("Warning 2");
    SQLWarning ex2 = new SQLWarning("Warning 3", t2);
    ex.setNextWarning(ex1);
    ex.setNextWarning(ex2);
    int num = 0;
    SQLWarning sqe = ex;
    while (sqe != null) {
        assertTrue(warnings[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextWarning();
    }
}
Also used : SQLWarning(java.sql.SQLWarning) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 12 with SQLWarning

use of java.sql.SQLWarning in project jdk8u_jdk by JetBrains.

the class SQLWarningTests method test6.

/**
     * Create SQLWarning with message, SQLState, and Throwable
     */
@Test
public void test6() {
    SQLWarning ex = new SQLWarning(reason, state, t);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == 0);
}
Also used : SQLWarning(java.sql.SQLWarning) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 13 with SQLWarning

use of java.sql.SQLWarning in project adempiere by adempiere.

the class DB method printWarning.

//	isRemoteProcess
/**************************************************************************
	 *	Print SQL Warnings.
	 *  <br>
	 *		Usage: DB.printWarning("comment", rs.getWarnings());
	 *  @param comment comment
	 *  @param warning warning
	 */
public static void printWarning(String comment, SQLWarning warning) {
    if (comment == null || warning == null || comment.length() == 0)
        throw new IllegalArgumentException("Required parameter missing");
    log.warning(comment);
    //
    SQLWarning warn = warning;
    while (warn != null) {
        StringBuffer buffer = new StringBuffer();
        buffer.append(warn.getMessage()).append("; State=").append(warn.getSQLState()).append("; ErrorCode=").append(warn.getErrorCode());
        log.warning(buffer.toString());
        warn = warn.getNextWarning();
    }
}
Also used : SQLWarning(java.sql.SQLWarning)

Example 14 with SQLWarning

use of java.sql.SQLWarning in project robovm by robovm.

the class OldConnectionTest method testClearWarnings.

// TODO clearWarnings is not supported
public void testClearWarnings() throws Exception {
    SQLWarning w = conn.getWarnings();
    assertNull(w);
    Statement st = null;
    try {
        st = conn.createStatement();
        st.execute("select animals from zoo");
        fail("SQLException was not thrown");
    } catch (SQLException e) {
        assertNotNull(conn.getWarnings());
    } finally {
        try {
            st.close();
        } catch (SQLException ee) {
        }
    }
    conn.clearWarnings();
    w = conn.getWarnings();
    assertNull(w);
    try {
        st = conn.createStatement();
        st.execute("select monkey from zoo");
        fail("SQLException was not thrown");
    } catch (SQLException e) {
        assertEquals("SQLite.Exception: error in prepare/compile", e.getMessage());
    } finally {
        try {
            st.close();
        } catch (SQLException ee) {
        }
    }
    //Test for correct functionality
    w = conn.getWarnings();
    assertNotNull(w);
    conn.close();
    try {
        conn.clearWarnings();
        fail("Exception expected");
    } catch (SQLException e) {
    //ok
    }
}
Also used : SQLWarning(java.sql.SQLWarning) SQLException(java.sql.SQLException) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) PreparedStatement(java.sql.PreparedStatement)

Example 15 with SQLWarning

use of java.sql.SQLWarning in project robovm by robovm.

the class OldStatementTest method testClearWarnings.

public void testClearWarnings() throws SQLException {
    Statement st = null;
    try {
        st = conn.createStatement();
        st.execute("select animals from zoo");
    } catch (SQLException e) {
    // expected
    } finally {
        try {
            st.close();
        } catch (SQLException ee) {
        }
    }
    try {
        st = conn.createStatement();
        st.clearWarnings();
        SQLWarning w = st.getWarnings();
        assertNull(w);
    } finally {
        try {
            st.close();
        } catch (SQLException ee) {
        }
    }
}
Also used : SQLWarning(java.sql.SQLWarning) SQLException(java.sql.SQLException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement)

Aggregations

SQLWarning (java.sql.SQLWarning)147 SQLException (java.sql.SQLException)47 Statement (java.sql.Statement)35 PreparedStatement (java.sql.PreparedStatement)30 Connection (java.sql.Connection)24 ResultSet (java.sql.ResultSet)23 Test (org.testng.annotations.Test)19 Test (org.junit.Test)17 BaseTest (util.BaseTest)15 CallableStatement (java.sql.CallableStatement)13 ArrayList (java.util.ArrayList)9 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)8 ResultSetMetaData (java.sql.ResultSetMetaData)6 Expectations (org.jmock.Expectations)6 IOException (java.io.IOException)4 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)3 PrestoWarning (com.facebook.presto.spi.PrestoWarning)3 HashSet (java.util.HashSet)3 Properties (java.util.Properties)3 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)3