急救:如何将文件流存入到oracle数据库的BLOB字段中?

dadapeer110 2009-02-04 09:51:52
各位大虾请救急!!!!
我想将多张图片压缩成ZIP格式,一起上传到数据库中的blob字段中。
下面的类2是将图片的ZIP包,解压得到每张图片的inputstream。类1是将inputstream存入到数据库中。
可是在程序的执行过程中。不报任何错误。但图片也存入不到数据库中。可是我确可以将inputstream写到文件中,还是原来的JPG图片。
请各位高手指教一下,为何我这个图片inputstream存不到数据库中




类1:
/**
* 执行图片更新语句
* 将文件流存入到数据中的blob字段中
* @return
*/
public boolean upSQL(String sql,InputStream inputstream,int size)throws Exception{
boolean b=false;


if (conn == null) {
conn = getConnection();
}

try {
if (preparedstatement == null)
preparedstatement = conn.prepareStatement(sql);
preparedstatement.setBinaryStream(1,inputstream, size);
preparedstatement.execute();
commit();
b=true;

} catch (Exception e) {
b=false;
e.printStackTrace();
if (autoCommit)
rollback();
Syslog.getInstance().logError(null, 1, "--执行sql操作语句upSQL(" + sql + ")操作异常!", e);

} finally {
close(conn);
close(preparedstatement);
}
//System.out.println("返回的操作::::::"+b);
return b;
}


类2:
/**
* 图片上传控制类
*将多张图片压缩成ZIP格式。 *
*
*
*/
public class LargephotoAction extends Action {
@SuppressWarnings("deprecation")
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse res) throws Exception {
boolean b = false;
String sql = null;
DBOperate code = null;
String sqlbob = null;
String path = "D:/";

ResultSet rs = null;


MultipartRequestHandler handler = form.getMultipartRequestHandler();
Hashtable file = handler.getFileElements();
Enumeration files = file.keys();
System.out.println("filekeys:::::::" + files);

code = new DBOperate();
while (files.hasMoreElements()) {
FormFile f = (FormFile) file.get(files.nextElement());
String af = f.getFileName().substring(0,
f.getFileName().lastIndexOf("."));
path += "\\" + af + "\\";
FileOperator.createFolder(path);
boolean ba =FileOperator.WriteFileByByte(f
.getInputStream(), path + f.getFileName());
File fi = new File(path + f.getFileName());

ZipFile zipFile = new ZipFile(fi);
Enumeration e = zipFile.getEntries();

while (e.hasMoreElements()) {
ZipEntry entry = (ZipEntry) e.nextElement();
String fileName = entry.getName();
InputStream inputStream = zipFile.getInputStream(entry);
String ls=fileName.substring(0, fileName.lastIndexOf("-"));
sqlbob = "update " + "tableA" + " set " +"BLOBNAME(Blob字段名称)" + " = ? where ID = '" + ls+"'";
long size = FileOperator.getStreamSize(inputStream);
b=类1.upSQL(sqlbob, inputStream,(int)size);此处调用类1中的方法
}
zipFile.close();
}

if (b) {
return mapping.findForward("sucess");
} else {
return mapping.findForward("unsucess");
}

}
}
...全文
530 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
superjava_2006 2009-02-05
  • 打赏
  • 举报
回复
执行不报错,却插不进去数据,不清楚怎么回事。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧