不同的数据库对Blob的操作有差别,因为有些JDBC接口方法有的数据库厂商未实现,一般用
PreparedStatement pstmt = con.prepareStatement("...");
File f = new File("文件名");
FileInputStream fis = new FileInputStream(f);
pstmt.setBinaryStream(1, fis, f.length);
是可行的。
PreparedStatement pstmt = con.prepareStatement("...");
File f = new File("文件名");
FileInputStream fis = new FileInputStream(f);
pstmt.setBinaryStream(1, fis, f.length);
是可行的。
解决方案 »
- 求解n元一次不定方程解法
- 谁有用java awt 做的图片旋转功能哦
- 从一个数组中随机不重复的选择多个元素
- 一个面试题(关于N张扑克牌能不能连成顺子)
- 根据配置文件如何加载一个类
- java如何调用c 的dll
- 如何利用struts 上传和下载文件 并且把路径存入数据库??急急急急急急
- JNI 本地接口调用C++ 方法时,CDC HDC HWND 这些参数怎么转换啊 ? 急!
- 用java实现手机短信的收发机费,想采用PC-通信提供服务接口--GSM网络数据传输-手机终端
- 求助!jave压缩视频出错! swScaler: Unknown format is not supported as input format
- 关于给程序打包的问题
- 如何序列化GeneralPath对象!
<jsp:useBean id="fileUpload" scope="page" class="com.xh.upload.SmartUpload" />
con.setAutoCommit(false);
try
{
PreparedStatement preStmt=con.prepareStatement("insert into file_fujian (file_id,note,filename,filesize) values(?,EMPTY_BLOB(),?,?)"); //首先针对每个附件产生一条记录
for(int i=0;i<fileUpload.getFiles().getCount();i++)
{
int f_id=0;//附件的id //判断附件是否有效
if(fileUpload.getFiles().getFile(i).isMissing())
{
continue;
} if(fileUpload.getFiles().getFile(i).getSize()<=0)
{
continue;
}
preStmt.setInt(1,info_id);
preStmt.setString(2,fileUpload.getFiles().getFile(i).getFileName());
preStmt.setInt(3,fileUpload.getFiles().getFile(i).getSize());
preStmt.execute();
//取得当前附件的id
Statement tempStmt=con.createStatement();
ResultSet temprs=tempStmt.executeQuery("select fujian_id.CURRVAL from dual");
if(temprs.next())
{
f_id=temprs.getInt(1);
} byte binBytes[] = new byte[fileUpload.getFiles().getFile(i).getSize()];
for (int j=0;j <fileUpload.getFiles().getFile(i).getSize();j++)
{
binBytes[j] = fileUpload.getFiles().getFile(i).getBinaryData(j);
} temprs=tempStmt.executeQuery("select * from file_fujian where id="+f_id);
//将附件写入
if (temprs.next())
{
BLOB blob = ((OracleResultSet) temprs).getBLOB("note");
OutputStream ost = blob.getBinaryOutputStream();
ost.write(binBytes);
ost.flush();
ost.close();
}
temprs.close();
}
con.commit();
flag=true;
}catch(Exception ex)
{
System.out.println(ex.getMessage());
con.rollback();
flag=false;
}