use of java.sql.Blob in project robovm by robovm.
the class OldPreparedStatementTest method testSetBlob.
public void testSetBlob() {
ResultSet res = null;
PreparedStatement ps = null;
Blob mock = new MockBlob();
try {
String neverExecutedQuery = "select TBlob from type;";
ps = conn.prepareStatement(neverExecutedQuery);
ps.setBlob(1, mock);
fail("Exception expected not supported");
} catch (SQLException e) {
//ok
}
}
use of java.sql.Blob in project spring-framework by spring-projects.
the class JdbcUtils method getResultSetValue.
/**
* Retrieve a JDBC column value from a ResultSet, using the most appropriate
* value type. The returned value should be a detached value object, not having
* any ties to the active ResultSet: in particular, it should not be a Blob or
* Clob object but rather a byte array or String representation, respectively.
* <p>Uses the {@code getObject(index)} method, but includes additional "hacks"
* to get around Oracle 10g returning a non-standard object for its TIMESTAMP
* datatype and a {@code java.sql.Date} for DATE columns leaving out the
* time portion: These columns will explicitly be extracted as standard
* {@code java.sql.Timestamp} object.
* @param rs is the ResultSet holding the data
* @param index is the column index
* @return the value object
* @throws SQLException if thrown by the JDBC API
* @see java.sql.Blob
* @see java.sql.Clob
* @see java.sql.Timestamp
*/
public static Object getResultSetValue(ResultSet rs, int index) throws SQLException {
Object obj = rs.getObject(index);
String className = null;
if (obj != null) {
className = obj.getClass().getName();
}
if (obj instanceof Blob) {
Blob blob = (Blob) obj;
obj = blob.getBytes(1, (int) blob.length());
} else if (obj instanceof Clob) {
Clob clob = (Clob) obj;
obj = clob.getSubString(1, (int) clob.length());
} else if ("oracle.sql.TIMESTAMP".equals(className) || "oracle.sql.TIMESTAMPTZ".equals(className)) {
obj = rs.getTimestamp(index);
} else if (className != null && className.startsWith("oracle.sql.DATE")) {
String metaDataClassName = rs.getMetaData().getColumnClassName(index);
if ("java.sql.Timestamp".equals(metaDataClassName) || "oracle.sql.TIMESTAMP".equals(metaDataClassName)) {
obj = rs.getTimestamp(index);
} else {
obj = rs.getDate(index);
}
} else if (obj instanceof java.sql.Date) {
if ("java.sql.Timestamp".equals(rs.getMetaData().getColumnClassName(index))) {
obj = rs.getTimestamp(index);
}
}
return obj;
}
use of java.sql.Blob in project hibernate-orm by hibernate.
the class LobCreatorTest method testLobCreation.
private void testLobCreation(LobCreator lobCreator) throws SQLException {
Blob blob = lobCreator.createBlob(new byte[] {});
if (lobCreator == NonContextualLobCreator.INSTANCE) {
assertTrue(blob instanceof BlobImplementer);
} else {
assertTrue(blob instanceof JdbcBlob);
}
blob = lobCreator.wrap(blob);
assertTrue(blob instanceof WrappedBlob);
Clob clob = lobCreator.createClob("Hi");
if (lobCreator == NonContextualLobCreator.INSTANCE) {
assertTrue(clob instanceof ClobImplementer);
} else {
assertTrue(clob instanceof JdbcClob);
}
clob = lobCreator.wrap(clob);
assertTrue(clob instanceof WrappedClob);
Clob nclob = lobCreator.createNClob("Hi");
if (lobCreator == NonContextualLobCreator.INSTANCE) {
assertTrue(nclob instanceof NClobImplementer);
} else {
assertTrue(nclob instanceof JdbcNClob);
}
assertTrue(NClob.class.isInstance(nclob));
nclob = lobCreator.wrap(nclob);
assertTrue(nclob instanceof WrappedClob);
blob.free();
clob.free();
nclob.free();
}
use of java.sql.Blob in project hibernate-orm by hibernate.
the class JpaLargeBlobTest method jpaBlobStream.
@Test
public void jpaBlobStream() throws Exception {
Session session = openSession();
LobEntity o = new LobEntity();
LobHelper lh = session.getLobHelper();
LobInputStream lis = new LobInputStream();
session.getTransaction().begin();
Blob blob = lh.createBlob(lis, LobEntity.BLOB_LENGTH);
o.setBlob(blob);
// Regardless if NON_CONTEXTUAL_LOB_CREATION is set to true,
// ContextualLobCreator should use a NonContextualLobCreator to create
// a blob Proxy. If that's the case, the InputStream will not be read
// until it's persisted with the JDBC driver.
// Although HHH-7698 was about high memory consumption, this is the best
// way to test that the high memory use is being prevented.
assertFalse(lis.wasRead());
session.persist(o);
session.getTransaction().commit();
assertTrue(lis.wasRead());
session.close();
lis.close();
}
use of java.sql.Blob in project Lucee by lucee.
the class SQLUtil method toBlob.
/**
* create a blog Object
* @param conn
* @param value
* @return
* @throws PageException
* @throws SQLException
*/
public static Blob toBlob(Connection conn, Object value) throws PageException, SQLException {
if (value instanceof Blob)
return (Blob) value;
// Java >= 1.6
if (SystemUtil.JAVA_VERSION >= SystemUtil.JAVA_VERSION_1_6) {
try {
Blob blob = conn.createBlob();
blob.setBytes(1, Caster.toBinary(value));
return blob;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
return BlobImpl.toBlob(value);
}
}
// Java < 1.6
if (isOracle(conn)) {
Blob blob = OracleBlob.createBlob(conn, Caster.toBinary(value), null);
if (blob != null)
return blob;
}
return BlobImpl.toBlob(value);
}
Aggregations