Search in sources :

Example 16 with Clob

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

the class FilterChainTest_Clob method test_resultSet_getObject_3.

public void test_resultSet_getObject_3() throws Exception {
    FilterChainImpl chain = new FilterChainImpl(dataSource);
    Clob clob = (Clob) chain.resultSet_getObject(new ResultSetProxyImpl(statement, mockResultSet, 1, null), "1", Collections.<String, Class<?>>emptyMap());
    Assert.assertTrue(clob instanceof ClobProxy);
    Assert.assertEquals(1, invokeCount);
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) ClobProxy(com.alibaba.druid.proxy.jdbc.ClobProxy) MockClob(com.alibaba.druid.mock.MockClob) Clob(java.sql.Clob) ResultSetProxyImpl(com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)

Example 17 with Clob

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

the class FilterChainTest_Clob method test_resultSet_getObject.

public void test_resultSet_getObject() throws Exception {
    FilterChainImpl chain = new FilterChainImpl(dataSource);
    Clob clob = (Clob) chain.resultSet_getObject(new ResultSetProxyImpl(statement, mockResultSet, 1, null), 1);
    Assert.assertTrue(clob instanceof ClobProxy);
    Assert.assertEquals(1, invokeCount);
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) ClobProxy(com.alibaba.druid.proxy.jdbc.ClobProxy) MockClob(com.alibaba.druid.mock.MockClob) Clob(java.sql.Clob) ResultSetProxyImpl(com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)

Example 18 with Clob

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

the class FilterChainTest_NClob_2 method test_getObject_3.

public void test_getObject_3() throws Exception {
    FilterChainImpl chain = new FilterChainImpl(dataSource);
    Clob clob = (Clob) chain.callableStatement_getObject(statement, "1", Collections.<String, Class<?>>emptyMap());
    Assert.assertTrue(clob instanceof NClobProxy);
    Assert.assertEquals(1, invokeCount);
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) NClobProxy(com.alibaba.druid.proxy.jdbc.NClobProxy) MockNClob(com.alibaba.druid.mock.MockNClob) Clob(java.sql.Clob)

Example 19 with Clob

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

the class FilterChainTest_NClob_2 method test_getObject_2.

public void test_getObject_2() throws Exception {
    FilterChainImpl chain = new FilterChainImpl(dataSource);
    Clob clob = (Clob) chain.callableStatement_getObject(statement, 1, Collections.<String, Class<?>>emptyMap());
    Assert.assertTrue(clob instanceof NClobProxy);
    Assert.assertEquals(1, invokeCount);
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) NClobProxy(com.alibaba.druid.proxy.jdbc.NClobProxy) MockNClob(com.alibaba.druid.mock.MockNClob) Clob(java.sql.Clob)

Example 20 with Clob

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

the class ClobTest method test_clob.

public void test_clob() throws Exception {
    Connection conn = null;
    PreparedStatement pstmt = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        conn = DriverManager.getConnection(create_url);
        pstmt = conn.prepareStatement("INSERT INTO T_CLOB (ID, DATA) VALUES (?, ?)");
        Clob clob = conn.createClob();
        ClobProxy clobWrapper = (ClobProxy) clob;
        Assert.assertNotNull(clobWrapper.getConnectionWrapper());
        clob.setAsciiStream(1);
        clob.setCharacterStream(1);
        clob.setString(1, "ABCAAAAAAAAAAA");
        clob.setString(1, "ABCAAAAAAAAAAA", 1, 5);
        pstmt.setInt(1, 1);
        pstmt.setClob(2, clob);
        int updateCount = pstmt.executeUpdate();
        Assert.assertEquals(1, updateCount);
        pstmt.setInt(1, 1);
        pstmt.setClob(2, new StringReader("XXXXXXX"));
        updateCount = pstmt.executeUpdate();
        Assert.assertEquals(1, updateCount);
        pstmt.setInt(1, 1);
        pstmt.setClob(2, new StringReader("ABCAAAAAAAAAAABCAAAAAAAAAAAAABCAAAAAAAAAAABCAAAAAAAAAAAA"), "ABCAAAAAAAAAAABCAAAAAAAAAAAAABCAAAAAAAAAAABCAAAAAAAAAAAA".length());
        updateCount = pstmt.executeUpdate();
        Assert.assertEquals(1, updateCount);
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
        // //////
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        // just call
        rs.getStatement();
        while (rs.next()) {
            Clob readClob = rs.getClob(2);
            readClob.length();
            readClob.position("abc", 1);
            readClob.getCharacterStream().close();
            readClob.getAsciiStream().close();
            readClob.getCharacterStream(1, 1).close();
            readClob.getSubString(1, 2);
            readClob.truncate(2);
            readClob.free();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.getCharacterStream(2).close();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.getCharacterStream("DATA").close();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            Clob searchstr = conn.createClob();
            searchstr.setString(1, "AB");
            Clob x = rs.getClob("DATA");
            x.position(searchstr, 1);
            x.free();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.getAsciiStream(2).close();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.getAsciiStream("DATA").close();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            Clob x = conn.createClob();
            x.setString(1, "XXSDDSLF");
            rs.updateClob(2, x);
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            Clob x = conn.createClob();
            x.setString(1, "XXSDDSLF");
            rs.updateClob("DATA", x);
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.updateClob(2, new StringReader("XDSFLA"));
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.updateClob("DATA", new StringReader("XDSFLA"));
        }
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.updateClob(2, new StringReader("XDSFLA"), "XDSFLA".length());
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.updateClob("DATA", new StringReader("XDSFLA"), "XDSFLA".length());
        }
        JdbcUtils.close(rs);
    } finally {
        JdbcUtils.close(rs);
        JdbcUtils.close(stmt);
        JdbcUtils.close(pstmt);
        JdbcUtils.close(conn);
    }
}
Also used : ClobProxy(com.alibaba.druid.proxy.jdbc.ClobProxy) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) StringReader(java.io.StringReader) PreparedStatement(java.sql.PreparedStatement) Clob(java.sql.Clob)

Aggregations

Clob (java.sql.Clob)96 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)27 Blob (java.sql.Blob)24 SQLException (java.sql.SQLException)20 ResultSet (java.sql.ResultSet)16 NClob (java.sql.NClob)14 MockClob (com.alibaba.druid.mock.MockClob)13 ClobProxy (com.alibaba.druid.proxy.jdbc.ClobProxy)13 MockNClob (com.alibaba.druid.mock.MockNClob)12 NClobProxy (com.alibaba.druid.proxy.jdbc.NClobProxy)12 ResultSetProxyImpl (com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)12 PreparedStatement (java.sql.PreparedStatement)10 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 Reader (java.io.Reader)7 Test (org.junit.Test)7 StringReader (java.io.StringReader)6 Connection (java.sql.Connection)6 Timestamp (java.sql.Timestamp)5 CUBRIDOIDProxy (com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy)4