@SuppressWarnings("deprecation") protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException { Blob blob = rs.getBlob(column); // get blob if (blob == null) { throw new SQLException("Driver's Blob representation is null!"); } if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob? ((oracle.sql.BLOB) blob).putBytes(1, data); ((oracle.sql.BLOB) blob).trim(data.length); return blob; } else { throw new SQLException( "Driver's Blob representation is of an unsupported type: " + blob.getClass().getName()); } } }
@SuppressWarnings("deprecation") protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException { Blob blob = rs.getBlob(column); // get blob if (blob == null) { throw new SQLException("Driver's Blob representation is null!"); } if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob? ((oracle.sql.BLOB) blob).putBytes(1, data); ((oracle.sql.BLOB) blob).trim(data.length); return blob; } else { throw new SQLException( "Driver's Blob representation is of an unsupported type: " + blob.getClass().getName()); } } }
rset.next(); Blob bobj = rset.getBlob(1); BLOB object = (BLOB) bobj; int chunkSize = object.getChunkSize(); byte[] binaryBuffer = new byte[chunkSize]; int position = 1; int bytesRead = 0; int bytesWritten = 0, totbytesRead = 0, totbytesWritten = 0; InputStream is = fileItem.getInputStream(); while ((bytesRead = is.read(binaryBuffer)) != -1) { bytesWritten = object.putBytes(position, binaryBuffer, bytesRead); position += bytesRead; totbytesRead += bytesRead; totbytesWritten += bytesWritten; is.close();
@SuppressWarnings("deprecation") protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQLException { Blob blob = rs.getBlob(column); // get blob if (blob == null) { throw new SQLException("Driver's Blob representation is null!"); } if (blob instanceof oracle.sql.BLOB) { // is it an oracle blob? ((oracle.sql.BLOB) blob).putBytes(1, data); ((oracle.sql.BLOB) blob).trim(data.length); return blob; } else { throw new SQLException( "Driver's Blob representation is of an unsupported type: " + blob.getClass().getName()); } } }
/** * INTERNAL: * Write LOB value - only on Oracle8 and up */ @SuppressWarnings("deprecation") public void writeLOB(DatabaseField field, Object value, ResultSet resultSet, AbstractSession session) throws SQLException { if (isBlob(field.getType())) { //change for 338585 to use getName instead of getNameDelimited oracle.sql.BLOB blob = (oracle.sql.BLOB)resultSet.getObject(field.getName()); //we could use the jdk 1.4 java.nio package and use channel/buffer for the writing //for the time being, simply use Oracle api. blob.putBytes(1, (byte[])value); //impose the locallization session.log(SessionLog.FINEST, SessionLog.SQL, "write_BLOB", Long.valueOf(blob.length()), field.getName()); } else if (isClob(field.getType())) { //change for 338585 to use getName instead of getNameDelimited oracle.sql.CLOB clob = (oracle.sql.CLOB)resultSet.getObject(field.getName()); //we could use the jdk 1.4 java.nio package and use channel/buffer for the writing //for the time being, simply use Oracle api. clob.putString(1, (String)value); //impose the locallization session.log(SessionLog.FINEST, SessionLog.SQL, "write_CLOB", Long.valueOf(clob.length()), field.getName()); } else { //do nothing for now, open to BFILE or NCLOB types } }
if (blob != null) blob.putBytes(1, bytes);
blob.putBytes(1, bytes); // Deprecated but what can you do