我用java程序将图片存入oracle数据库的blob字段,但读出来存成图片文件后,windows不能预览,用画图和图片浏览器不能打开,但用photoshop能打开.
这是写入数据库的代码:
String sqlRs = "select zp from ts_jgzp where zpdm='" + phName +
"' and xh='"+(tot+1)+"' for update";
rs = stmt.executeQuery(sqlRs);
if (rs.next()) {
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
outStream.write(photo);
outStream.flush();
outStream.close();
log = "0^0^";
}
使用plsql导出图片也是不能正常打开,只能用photoshop看
这是写入数据库的代码:
String sqlRs = "select zp from ts_jgzp where zpdm='" + phName +
"' and xh='"+(tot+1)+"' for update";
rs = stmt.executeQuery(sqlRs);
if (rs.next()) {
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
outStream.write(photo);
outStream.flush();
outStream.close();
log = "0^0^";
}
使用plsql导出图片也是不能正常打开,只能用photoshop看
这里你写的好像是直接写入一个对象啊,你取图片文件的字节,按照字节存进去,取出的时候也按照字节取,这样肯定就不会有问题的。
基本写法如下
BufferedInputStream bis = null;
bis = new BufferedInputStream(new FileInputStream(photo));
byte[] data = new byte[8192];
while((count = bis.read(data)) != -1){
outStream.write(data,0,count);
}
一下子写入整个文件,会有问题的。
另外证明ps真的很强,什么都能读出来