我正在使用ApacheMetaModel
toExtract
和数据库Restore
中的数据Oracle
。我将Extracting
数据输入CSV
并Restoring
从CSV
数据库中返回数据。很少有表有Clob
和Blob
数据。
当Extracting
来自 的数据时Oracle
,我将其转换BLOB
为 ,String
因此可以将其写入文本文件(CSV)。
Blob blob = (Blob) value; // blob value of oracle database
byte[] bytes = IOUtils.toByteArray(blob.getBinaryStream());
insert.value(column, new String(bytes)); // insert into csv
BLOB
(作为字符串)被成功提取。
现在为了将它恢复到数据库中,我正在做相反的事情
InputStream stream = new ByteArrayInputStream(value.getBytes()); // read value from csv and convert it into the stream.
byte[] bytes = org.apache.poi.util.IOUtils.toByteArray(stream); // convert stream to bytes
Blob blob = connection.createBlob(); // create a blob
blob.setBytes(1, bytes); // put bytes into the blob
insert.value(column, blob); // insert blob into database
当我使用它检查恢复的数据到目标数据库时,Oracle SQL Developer
它显示数据已损坏。
image could not be decoded from the binary stream
请帮助我将 BLOB 数据提取到 CSV 并从 CSV 恢复回数据库。