Search in sources :

Example 6 with NClob

use of java.sql.NClob in project jdbc-shards by wplatform.

the class LobApiTestCase method testClob.

private void testClob(int length) throws Exception {
    Random r = new Random(length);
    char[] data = new char[length];
    // (String.getBytes("UTF-8") only returns 1 byte for 0xd800-0xdfff)
    for (int i = 0; i < length; i++) {
        char c;
        do {
            c = (char) r.nextInt();
        } while (c >= 0xd800 && c <= 0xdfff);
        data[i] = c;
    }
    Clob c = conn.createClob();
    Writer out = c.setCharacterStream(1);
    out.write(data, 0, data.length);
    out.close();
    stat.execute("delete from test");
    PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?)");
    prep.setInt(1, 1);
    prep.setClob(2, c);
    prep.execute();
    c = conn.createClob();
    c.setString(1, new String(data));
    prep.setInt(1, 2);
    prep.setClob(2, c);
    prep.execute();
    prep.setInt(1, 3);
    prep.setCharacterStream(2, new StringReader(new String(data)));
    prep.execute();
    prep.setInt(1, 4);
    prep.setCharacterStream(2, new StringReader(new String(data)), -1);
    prep.execute();
    NClob nc;
    nc = conn.createNClob();
    nc.setString(1, new String(data));
    prep.setInt(1, 5);
    prep.setNClob(2, nc);
    prep.execute();
    prep.setInt(1, 5);
    prep.setNClob(2, new StringReader(new String(data)));
    prep.execute();
    prep.setInt(1, 6);
    prep.setNClob(2, new StringReader(new String(data)), -1);
    prep.execute();
    prep.setInt(1, 7);
    prep.setNString(2, new String(data));
    prep.execute();
    ResultSet rs;
    rs = stat.executeQuery("select * from test");
    rs.next();
    Clob c2 = rs.getClob(2);
    assertEquals(length, c2.length());
    String s = c.getSubString(1, length);
    String s2 = c2.getSubString(1, length);
    while (rs.next()) {
        c2 = rs.getClob(2);
        assertEquals(length, c2.length());
        s2 = c2.getSubString(1, length);
        assertEquals(s, s2);
    }
}
Also used : NClob(java.sql.NClob) Random(java.util.Random) StringReader(java.io.StringReader) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) NClob(java.sql.NClob) Clob(java.sql.Clob) Writer(java.io.Writer)

Example 7 with NClob

use of java.sql.NClob in project hibernate-orm by hibernate.

the class ResourceRegistryStandardImpl method releaseResources.

@Override
public void releaseResources() {
    log.trace("Releasing JDBC resources");
    for (Map.Entry<Statement, Set<ResultSet>> entry : xref.entrySet()) {
        if (entry.getValue() != null) {
            closeAll(entry.getValue());
        }
        close(entry.getKey());
    }
    xref.clear();
    closeAll(unassociatedResultSets);
    if (blobs != null) {
        for (Blob blob : blobs) {
            try {
                blob.free();
            } catch (SQLException e) {
                log.debugf("Unable to free JDBC Blob reference [%s]", e.getMessage());
            }
        }
        blobs.clear();
    }
    if (clobs != null) {
        for (Clob clob : clobs) {
            try {
                clob.free();
            } catch (SQLException e) {
                log.debugf("Unable to free JDBC Clob reference [%s]", e.getMessage());
            }
        }
        clobs.clear();
    }
    if (nclobs != null) {
        for (NClob nclob : nclobs) {
            try {
                nclob.free();
            } catch (SQLException e) {
                log.debugf("Unable to free JDBC NClob reference [%s]", e.getMessage());
            }
        }
        nclobs.clear();
    }
}
Also used : NClob(java.sql.NClob) Blob(java.sql.Blob) Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException) Statement(java.sql.Statement) NClob(java.sql.NClob) Clob(java.sql.Clob) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with NClob

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

the class ResultSetProxyImpl method getNClob.

@Override
public NClob getNClob(String columnLabel) throws SQLException {
    FilterChainImpl chain = createChain();
    NClob value = chain.resultSet_getNClob(this, columnLabel);
    recycleFilterChain(chain);
    return value;
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) NClob(java.sql.NClob)

Example 9 with NClob

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

the class FilterChainImplTest method test_unwrap_6.

public void test_unwrap_6() throws Exception {
    Connection conn = dataSource.getConnection();
    Assert.assertTrue(new FilterChainImpl(dataSource).wrap((ConnectionProxy) dataSource.getConnection().getConnection(), new MockNClob()) instanceof NClob);
    conn.close();
}
Also used : MockNClob(com.alibaba.druid.mock.MockNClob) NClob(java.sql.NClob) FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) MockNClob(com.alibaba.druid.mock.MockNClob) Connection(java.sql.Connection)

Example 10 with NClob

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

the class FilterChainImplTest method test_unwrap_8.

public void test_unwrap_8() throws Exception {
    Connection conn = dataSource.getConnection();
    Assert.assertTrue(new FilterChainImpl(dataSource).wrap((ConnectionProxy) dataSource.getConnection().getConnection(), (Clob) new MockNClob()) instanceof NClob);
    conn.close();
}
Also used : MockNClob(com.alibaba.druid.mock.MockNClob) NClob(java.sql.NClob) FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) MockNClob(com.alibaba.druid.mock.MockNClob) Connection(java.sql.Connection)

Aggregations

NClob (java.sql.NClob)11 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)5 Clob (java.sql.Clob)5 Blob (java.sql.Blob)4 Connection (java.sql.Connection)3 ResultSet (java.sql.ResultSet)3 MockNClob (com.alibaba.druid.mock.MockNClob)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 JdbcParameter (com.alibaba.druid.proxy.jdbc.JdbcParameter)1 JSONWriter (com.alibaba.druid.support.json.JSONWriter)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 PreparedStatement (java.sql.PreparedStatement)1 SQLXML (java.sql.SQLXML)1 Savepoint (java.sql.Savepoint)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1