Search in sources :

Example 1 with SQLClientInfoException

use of java.sql.SQLClientInfoException in project tomcat by apache.

the class DelegatingConnection method setClientInfo.

@Override
public void setClientInfo(final Properties properties) throws SQLClientInfoException {
    try {
        checkOpen();
        _conn.setClientInfo(properties);
    } catch (final SQLClientInfoException e) {
        throw e;
    } catch (final SQLException e) {
        throw new SQLClientInfoException("Connection is closed.", EMPTY_FAILED_PROPERTIES, e);
    }
}
Also used : SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException)

Example 2 with SQLClientInfoException

use of java.sql.SQLClientInfoException in project druid by alibaba.

the class ConnectionTest method test_connection.

@SuppressWarnings("deprecation")
public void test_connection() throws Exception {
    Connection conn = null;
    PreparedStatement pstmt = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        conn = DriverManager.getConnection(create_url);
        conn.setCatalog(conn.getCatalog());
        conn.setClientInfo(conn.getClientInfo());
        conn.setHoldability(conn.getHoldability());
        conn.setReadOnly(conn.isReadOnly());
        conn.setTransactionIsolation(conn.getTransactionIsolation());
        conn.setTypeMap(conn.getTypeMap());
        try {
            conn.setClientInfo("name", "value");
        } catch (SQLClientInfoException ex) {
        }
        try {
            conn.createArrayOf("VARCHAR", new String[] { "A", "B" });
        } catch (SQLFeatureNotSupportedException ex) {
        }
        try {
            conn.createNClob();
        } catch (SQLFeatureNotSupportedException ex) {
        }
        try {
            conn.createSQLXML();
        } catch (SQLFeatureNotSupportedException ex) {
        }
        try {
            conn.createStruct("VARCHAR", new String[] { "A", "B" });
        } catch (SQLFeatureNotSupportedException ex) {
        }
        conn.setAutoCommit(false);
        Savepoint savePoint = conn.setSavepoint("XX");
        conn.releaseSavepoint(savePoint);
        pstmt = conn.prepareStatement("INSERT INTO T_BLOB (ID, DATA) VALUES (?, ?)");
        Blob blob = conn.createBlob();
        blob.setBytes(1, new byte[100]);
        pstmt.setInt(1, 1);
        pstmt.setBlob(2, blob);
        int updateCount = pstmt.executeUpdate();
        Assert.assertEquals(1, updateCount);
        stmt = conn.createStatement();
        conn.nativeSQL("SELECT ID, DATA FROM T_BLOB");
        // //////
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_BLOB");
        // just call
        rs.getStatement();
        while (rs.next()) {
            Blob readBlob = rs.getBlob(2);
            readBlob.length();
            readBlob.getBinaryStream(1, 100).close();
            readBlob.getBinaryStream().close();
            readBlob.free();
            try {
                rs.getUnicodeStream(1).close();
            } catch (SQLFeatureNotSupportedException ex) {
            }
            try {
                rs.getUnicodeStream("DATA").close();
            } catch (SQLFeatureNotSupportedException ex) {
            }
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_BLOB");
        while (rs.next()) {
            rs.getBinaryStream(2).close();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_BLOB");
        while (rs.next()) {
            rs.getBinaryStream("DATA").close();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_BLOB");
        while (rs.next()) {
            rs.getBytes(2);
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_BLOB");
        while (rs.next()) {
            rs.getBytes("DATA");
        }
        JdbcUtils.close(rs);
        conn.setAutoCommit(true);
    } finally {
        JdbcUtils.close(rs);
        JdbcUtils.close(stmt);
        JdbcUtils.close(pstmt);
        JdbcUtils.close(conn);
    }
}
Also used : SQLClientInfoException(java.sql.SQLClientInfoException) Blob(java.sql.Blob) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Savepoint(java.sql.Savepoint) Savepoint(java.sql.Savepoint)

Example 3 with SQLClientInfoException

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

the class SQLClientInfoExceptionTests method test8.

/**
     * Create SQLClientInfoException with message, SQLState, and error code
     */
@Test
public void test8() {
    SQLClientInfoException ex = new SQLClientInfoException(reason, state, errorCode, map, t);
    assertTrue(ex.getMessage().equals(reason) && ex.getSQLState().equals(state) && cause.equals(ex.getCause().toString()) && ex.getErrorCode() == errorCode && ex.getFailedProperties().equals(map));
}
Also used : SQLClientInfoException(java.sql.SQLClientInfoException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 4 with SQLClientInfoException

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

the class SQLClientInfoExceptionTests method test12.

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

Example 5 with SQLClientInfoException

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

the class SQLClientInfoExceptionTests method test10.

/**
     * Serialize a SQLClientInfoException and make sure you can read it back
     * properly
     */
@Test
public void test10() throws Exception {
    SQLClientInfoException e = new SQLClientInfoException(reason, state, errorCode, map, t);
    SQLClientInfoException ex1 = createSerializedException(e);
    assertTrue(reason.equals(ex1.getMessage()) && ex1.getSQLState().equals(state) && cause.equals(ex1.getCause().toString()) && ex1.getErrorCode() == errorCode && ex1.getFailedProperties().equals(map));
}
Also used : SQLClientInfoException(java.sql.SQLClientInfoException) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Aggregations

SQLClientInfoException (java.sql.SQLClientInfoException)17 Test (org.testng.annotations.Test)12 BaseTest (util.BaseTest)12 SQLException (java.sql.SQLException)5 SysProperties (com.wplatform.ddal.engine.SysProperties)1 DbException (com.wplatform.ddal.message.DbException)1 ValueString (com.wplatform.ddal.value.ValueString)1 Blob (java.sql.Blob)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 SQLWarning (java.sql.SQLWarning)1 Savepoint (java.sql.Savepoint)1 Statement (java.sql.Statement)1 Properties (java.util.Properties)1