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);
}
}
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();
}
}
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;
}
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();
}
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();
}
Aggregations