java byte[]转换blob
来源:互联网 发布:最小单片机系统 编辑:程序博客网 时间:2024/06/03 23:03
由于在开发中需要调用带有blob参数的存储过程,然后一直不知道怎么转换,最后找到这种方式应该可以转换,我还没有测试!不过不报错,我猜测百分之八十是可以了!对了这个针对hibernate4.3版本以后这么使用,因为org.hibernate.service.ServiceRegistryBuilder这个类被弃用了
//创建配置对象 Configuration configiguration = new Configuration().configure(); //创建服务注册对象 ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configiguration.getProperties()).build();//创建会话工厂对象 SessionFactory sf = configiguration.buildSessionFactory(serviceRegistry); //会话对象 Session session = sf.openSession(); //转换byte[]oracle.sql.BLOB blob=(BLOB) session.getLobHelper().createBlob(new byte[1024]);
hibernate4.3版本之前的这么使用
Configuration configiguration = new Configuration().configure(); ServiceRegistryBuilder builder = new ServiceRegistryBuilder().applySettings(configiguration.getProperties()); ServiceRegistry registry = builder.buildServiceRegistry(); SessionFactory sf = configiguration.buildSessionFactory(registry); Session session = sf.openSession(); oracle.sql.BLOB blob=(BLOB) session.getLobHelper().createBlob(new byte[1024]);
待我测试后,后续跟新是否可以
2017-08-31 14:30 跟新
刚测试完,测试结果不可以,因为:
使用spring整合hibernate之后,sessionFactory由spring管理,所以再用hibernate的Configuration conf = new Configuration().configure();就会找不到配置文件,这时候必须用spring的sessionFactory或者使用spring提供的hibernateTemplate,用sessionFactory不能管理事务,用hibernateTemplate能管理事务
如果你们在测试的时候报:org.hibernate.HibernateException: /hibernate.cfg.xml not found这个错误的时候,我想多半是这个原因!解决办法如下:
SessionFactory sf = hibernateTemplate.getSessionFactory();Session session = sf.openSession(); oracle.sql.BLOB blob=(BLOB) session.getLobHelper().createBlob(new byte[1024]);
当然需要在类装配
@Resource
private HibernateTemplate hibernateTemplate;
静待我测试归来
测试失败。。。。。。心塞中
我们项目不能采用hibernate!如果可以用的应该是可以!
阅读全文
0 0
- java byte[]转换blob
- java byte[]Blob转
- java byte[]Blob转
- java.sql.Blob、byte[]、InputStream之间的相互转换
- java.sql.Blob、byte[]、InputStream之间的相互转换
- Java类型相互转换byte[]类型,blob类型
- Java之Byte和blob相互转换(Oracle)-yellowcong
- InputStream、Blob、byte 互相转换方式
- Blob类型转换为byte数组类型
- Java中将byte[]转为Blob对象
- Java中将byte[]转为Blob对象
- java中将Oracle数据局中blob型数据转换为byte型的两种方法
- Java byte[] long 转换
- Java byte数据类型转换
- java byte转换int
- Java byte类型转换
- Java类型转换(int - byte[],float - byte[])
- Java类型转换(int - byte[],float - byte[])
- 前端命名规范及常用词汇
- [Android] Android自定义View修炼之路(1)
- 父类引用指向子类对象时变量传递问题
- appcan MVVM 中使用computeds对model属性进行扩展和处理
- [Android] Android自定义View修炼之路(2)
- java byte[]转换blob
- 工具,域名,主机,关键词
- [Android] Build.VERSION_CODES类下面的版本信息
- jvm hotspot gc 逻辑 脑图
- 常见的STL容器及其使用场景
- Json 格式 toJsonString
- Android使用ItemTouchHelper打造可拖拽的RecyclerView
- Vue keep-alive实践总结
- 面试问题spring cloud和dubbo的区别