将图像作为blob保存到Oracle表时,blob有时会被截断。
如果图像被截断,它总是在同一个地方被截断。
此外,这不是尺寸问题,这是第一个明显的答案。截断的一个图像是126Kb,一个很好的图像是3Mb
blob列没有指定大小,因此根据Oracle,它默认为2Gb。
java代码是:
OutputStream os = null;
try {
os = image.getImage().getBinaryOutputStream();
os.write(uploadFile.getFileData());
} catch (Exception e) {
af = mapping.findForward("imageProblem");
}
答案 0 :(得分:1)
这是因为我忘了关闭OutputStream。在将blob写入表格之前,它以一种令人惊讶的确定性方式被垃圾收集(我假设)。关闭流修复了问题:
OutputStream os = null;
try {
os = image.getImage().getBinaryOutputStream();
os.write(uploadFile.getFileData());
} catch (Exception e) {
af = mapping.findForward("imageProblem");
} finally {
if (os != null) {
os.close();
}
}