use of oracle.sql.BLOB in project jforum2 by rafaelsteil.
the class OracleUtils method writeBlobUTF16BinaryStream.
/**
* The query should look like:
*
* SELECT blob_field from any_table WHERE id = ? FOR UPDATE
*
* BUT KEEP IN MIND:
*
* When you insert record in previous step, it should go with empty_blob() like:
*
* INSERT INTO jforum_posts_text ( post_text ) VALUES (EMPTY_BLOB())
*
* @param query String
* @param idForQuery int
* @param value String
* @throws SQLException
*/
public static void writeBlobUTF16BinaryStream(String query, int idForQuery, String value) throws Exception {
PreparedStatement p = null;
ResultSet rs = null;
OutputStream blobWriter = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(query);
p.setInt(1, idForQuery);
rs = p.executeQuery();
rs.next();
Blob text = rs.getBlob(1);
if (text instanceof BLOB) {
blobWriter = ((BLOB) text).getBinaryOutputStream();
} else {
blobWriter = text.setBinaryStream(0);
}
blobWriter.write(value.getBytes("UTF-16"));
blobWriter.close();
} catch (IOException e) {
throw new DatabaseException(e);
} finally {
if (blobWriter != null) {
blobWriter.close();
}
DbUtils.close(rs, p);
}
}
Aggregations