hibernate4操作数据库blob案例
2015-09-17 11:45
477 查看
由于hibernate4废弃hibernate.createClob,只能采用getLobHelper获取,Hibernate4以下的版本均可采用hibernate.createClob
@Transactional
public int uploadCap(CommonsMultipartFile file,CapPackage capPackage){
InputStream fis=null;
byte[] content=null;
Transaction transaction=null;
Session session=null;
session = this.getSessionFactory().openSession();
try {
//将磁盘文件读入到输入流
fis=file.getInputStream();//new FileInputStream("C:\\Users\\wangkk\\Desktop\\1.sql");
//将输入流中的内容存储到字节数组中
content=new byte[fis.available()];
fis.read(content);
Blob blobContent= session.getLobHelper().createBlob(content);
capPackage.setCapContent(blobContent);
this.getHibernateTemplate().save(capPackage);
return 200;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return 0;
}
@Transactional
public int uploadCap(CommonsMultipartFile file,CapPackage capPackage){
InputStream fis=null;
byte[] content=null;
Transaction transaction=null;
Session session=null;
session = this.getSessionFactory().openSession();
try {
//将磁盘文件读入到输入流
fis=file.getInputStream();//new FileInputStream("C:\\Users\\wangkk\\Desktop\\1.sql");
//将输入流中的内容存储到字节数组中
content=new byte[fis.available()];
fis.read(content);
Blob blobContent= session.getLobHelper().createBlob(content);
capPackage.setCapContent(blobContent);
this.getHibernateTemplate().save(capPackage);
return 200;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return 0;
}
相关文章推荐
- Mac下通过Homebrew安装配置MySQL
- 运维进行时-修改数据库密码
- Ubuntu下mysql安装,登录
- Express调用mssql驱动公共类dbHelper
- mysql事件调度器
- NoSQL数据库:Redis适用场景及产品定位
- SQL Server 三大物理连接算法(嵌套,合并,哈希)的IO成本总结
- SQL Server中行列转换 Pivot UnPivot
- mysql 主从复制读写分离
- MySQL添加索引
- mysql备份
- SQL字符串操作汇总
- jdbc操作数据库blob
- oracle dblink 创建使用 垮库转移数据
- 在SQL Server Management Studio中打开BAK文件恢复数据库
- SET FOREIGN_KEY_CHECKS=0;在Mysql中取消外键约束
- sqlite数据的增删改查------Java代码
- oracle 存储过程
- mysql 权限基本操作
- 建一个Sqlite帮助类