hibernate 对于blob的操作

oracle数据库建表语句

create table stu
(
   id number(2),
   name varchar2(16),
   filename varchar2(64),
   filedata BLOB,
   primary key(id)
);

Stu.java文件

public class Stu implements java.io.Serializable {

 // Fields

 private Byte id;
 private String name;
 private String filename;
 private byte[]  filedata;  //此处理将其属性类型设为byte[]

 // Constructors

 /** default constructor */
 public Stu() {
 }

剩余部分略去.....

Stu.hbm.xml文件如下:

<hibernate-mapping>
    <class name="com.aoyou.mapping.Stu" table="STU" schema="LIXIN03080">
        <id name="id" type="java.lang.Byte">
            <column name="ID" precision="2" scale="0" />
            <generator class="assigned" />
        </id>
        <property name="name" type="java.lang.String">
            <column name="NAME" length="16" />
        </property>
        <property name="filename" type="java.lang.String">
            <column name="FILENAME" length="64" />
        </property>
        <!-- 注意下面filedata的type为binary -->
        <property name="filedata" type="binary">
            <column name="FILEDATA" />
        </property>
    </class>
</hibernate-mapping>
        <property name="filedata" type="binary">
            <column name="FILEDATA" />
        </property>
    </class>
</hibernate-mapping>

在main方法中测试:

保存数据到数据库:

public static void main(String[] args) throws IOException{
         Session session = new Configuration().configure().buildSessionFactory().openSession();
        Transaction t = session.beginTransaction();
  
        File file = new File("D:\\购物网站\\二期\\数据库设计.txt");
       BufferedReader br = new BufferedReader(new FileReader(file));
  
  
       Stu stu = new Stu();
       stu.setId(2);
       stu.setName("mary");
       stu.setFilename("数据清单");
  
       String content = "";
      String temp = "";
      while((temp = br.readLine()) != null){
            content += temp;
       }
       br.close();
       stu.setFiledata(content.getBytes());
       session.save(stu);
  
       t.commit();
 }

读取数据库数据:

public static void main(String[] args) throws IOException{
           Session session = new Configuration().configure().buildSessionFactory().openSession();
           Transaction t = session.beginTransaction();
  
           String hql = " from Stu  ";
           Query query = session.createQuery(hql);
           List list = query.list();
           if(list != null){
                   Stu stu = (Stu)list.get(0);
                  System.out.println(stu.getId());
                  System.out.println(stu.getName());
                  System.out.println(stu.getFilename());
                  byte[] b = stu.getFiledata();
                 System.out.print(new   String(b,   0,   b.length));
           }
  
       t.commit();
 }

Hibernate对BLOB CLOB操作 NULL 博文链接:https://ylsuccess.iteye.com/blog/411005 立即下载

相关推荐

关于在Hibernate中对于Clob,Blob字段的处理方法

oracle的jdbc驱动程序,用这个版本的操作Clob,blob类型的数据很方便。 博文链接:https://zhenjw.iteye.com/blog/173419

hibernate 创建blob对象

<br />用hibernate创建blob对象:<br /> Blob  blob=Hibernate.createBlob(Byte []);

gujian123456的专栏 1232

PDDL入门

PDDL的组成部分 Objects:对象,世界上我们感兴趣的事物。 Predicates:谓词,我们感兴趣的事实(例如对象的属性),可以为真,也可以为假。 An initial state:初始化状态,我们开始所处的世界状态,即开始时为真的事物。 Goal specification:目标状态,我们想要结束的世界的状态,即我们希望最终成为真实的事情。 Actions/Operators:动作/操作,改变世界状态的方式,即发生的事情改变了事实。 PDDL语法 PDDL 文件的扩展名通常是.pddl 要

工控小白2021的博客 4821

hibernate mysql clob_Hibernate实现Clob和Blob对象的存取

作为测试,我们新建一个TUser对象,其image属性中,保存了一个图片文件的二进制内容。而其resume属性,我们以一个简单的字符串作为填充。1TUseruser= new TUser();2 3user.setAge(new Integer( 20 ));4 5user.setName(" Shark ");6 7FilelnputStreamimgis= new FileinputS...

weixin_31040783的博客 390

VL53L1X移植到STM32实战记录,使用软件IIC(附源代码)

序言 VL53L1X是一个很小又很优秀的测距传感器,它相比于上一代VL53L0X有着不小的提升,这次毕业设计打算将这个传感器用起来,就来移植了一下,遇到的坑怎么说还是有一些,故在此分享给大家。 开发环境 IDE:Keil V5 STM32CubeMX ,使用HAL库 具体操作 获取官方库并进行移植 这一步是移植的基础,首先从官方把API库下下来,并添加到IDE中: 适配硬件 这里由于不同的硬件平...

wmdscjhdpy的博客 1万+

从零构建:四轴机械臂D-H参数建模与MATLAB实战指南

本文详细介绍了四轴机械臂D-H参数建模的完整流程与MATLAB实战应用。从机械臂运动学基础出发,解析D-H参数原理与坐标系建立规则,提供MATLAB Robotics Toolbox的安装、模型创建及正逆运动学求解的代码实现。特别针对四轴机械臂的逆运算优化、轨迹规划和奇异位形规避等高级应用给出实用解决方案,是机器人开发者的实战指南。

weixin_29062255的博客 419

Hibernate实现Clob和Blob对象的存取

1 TUser user  = new  TUser();  2  3 user.setAge( new  Integer( 20 ));  4  5 user.setName( " Shark " );  6  7 FilelnputStream imgis  = new  FileinputStream( " C://inimage.jpg "   8  9 Blob img  =

溺水的鱼 - Later equals never. 2127

RV1106G3的fastboot调试

本文详细描述了在幸狐的Luckfox Pico Ultra硬件平台上,使用官方SDK进行系统优化和YOLOv5s模型部署的过程。首先,硬件板卡使用幸狐的SDK进行EMMC非Fastboot配置时功能正常,但Fastboot配置编译失败,通过修改设备树中的ramdisk大小解决了编译问题,但运行时仍报错。幸狐提供的Fastboot烧录文件可正常运行,表明硬件支持Fastboot。随后,使用官方SDK版本rv1106_rv1103_240813进行编译和调试,发现EMMC Fastboot启动失败,通过修改U-

fzktongyong的博客 2354

Hibernate操作Blob数据

首先看数据库,数据库中新建一个BlobTable表,表中有两个字段,一个id(主键)一个picture字段是Blob类型字段。然后使用Hibernate向该数据库中写入和读取数据 在POJO类中picture属性用的是Blob类型数据。 下面看操作源码 package dao; import java.io.File; import java.io.FileInputStream; imp

翻滚吧小牛 2272

R语言实战:从Raw Counts到TPM/FPKM的完整转换指南(含代码调试技巧)

本文详细介绍了在R语言环境中将RNA-seq原始计数(raw counts)转换为TPM/FPKM值的完整流程,包含代码实现和常见错误调试技巧。通过具体案例演示如何正确处理基因长度和测序深度因素,实现表达量标准化,为生物信息学分析提供可靠数据基础。特别适合需要进行转录组数据分析的研究人员和实验室技术人员参考。

weixin_28559803的博客 477

Python电梯II

输入数据有若干组(最多不超过1000组),每组数据的第一行为四个如题目中所示的整数N,u,d,s,由空格分隔开。第二行为不同楼层需要上下楼的请求, 最多不超过1000个。每个请求的格式为"from-to",其中"from"和"to"为所在楼层和要到达的楼层,保证from!=to。

沐风—云端行者 909

[随记]在Hibernate中如何使用Blob数据类型

Blob数据类型 1)pojo定义时直接定义成 private Blob file; 2)hbm映射时 type=”blob” 3)数据库字段采用blob类型 4)写入时使用Hibernate.createBlob(fis); fis为FileInputStream 5)...

chuichansheng7987的博客 327

SpringBoot 插件化开发详细总结

SpringBoot 插件化开发方案总结

congge 1万+

spring hibernate mysql blob_使用Spring+hibernate透明操作blob(照片实例)

前言:Oracle的blob操作的复杂性我想很多人都见识过了,首先要插入一个空的blob以获得光标。。。。(此处省略n字)首先我们介绍hibernate的对应的配置:对应于数据库字段我们怎样定义hibernate 的hbm.xml和POJO,对应于BLOB 和CLOB,我们在hbm.xml的定义方式如下:BLOBàorg.springframework.orm.hibernate3.support...

weixin_39712016的博客 244

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

hibernate oracle blob,Hibernate3操作Oracle的Blob字段

Hibernate3操作Oracle的Blob字段hibernate作为一个优秀的OR-Mapping构架,对数据库的基本操作进行了比较好的封装,针对Blob类型字段的操作也不例外。但网上大部分能找到的hibernate操作Blob的例程都是基于hibernate2版本的,同时在实际操作中我发现针对不同的数据库,可以有不同的操作方法。下面将hibernate3操作oracle的Blob字段进行一个...

weixin_35628777的博客 456

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

使用hibernate透明操作blob

前言:Oracle的blob操作的复杂性我想很多人都见识过了,首先要插入一个空的blob以获得光标。。。。(此处省略n字) 首先我们介绍hibernate的对应的配置: 对应于数据库字段我们怎样定义hibernate 的hbm.xml和POJO,对应于BLOB 和CLOB,我们在hbm.xml的定义方式如下: BLOBàorg.springframework.orm.hibernate...

一元钱计划 183

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

通过JDBC和Hibernate对Clob和Blob的操作

通过JDBC和Hibernate对Clob和Blob的操作,插入和读取. 一,JDBC方式: 1,当lob的内容很小的时候,用sta.setString(2, "clob content"); sta.setBytes(3, "blob".getBytes()); 2,通过steam的方式写入内容: InputStream fis1 = new StringBuffer

shuimumu的专栏 497

hibernate 操作clob,blob对象

转自:http://hpingliu.blog.ccidnet.com/blog-htm-do-showone-type-blog-itemid-144245-uid-48802.html] 作为测试,我们新建一个TUser对象,其image属性中,保存了一个图片文件的二进制内容。而其resume属性,我们以一个简单的字符串作为填充。 1 TUser user = new TUser(); 2 3...

friping的专栏 194

hibernate3操作oracle的Blob字段

【老乔】hibernate作为一个优秀的OR-Mapping构架,对数据库的基本操作进行了比较好的封装,针对Blob类型字段的操作也不例外。但网上大部分能找到的hibernate操作Blob的例程都是基于hibernate2版本的,同时在实际操作中我发现针对不同的数据库,可以有不同的操作方法。下面将hibernate3操作oracle的Blob字段进行一个介绍。          用JDBC操作B...

wsrjzhsy0493的博客 301

Hibernate3操作Oracle的Blob字段

hibernate作为一个优秀的OR-Mapping构架,对数据库的基本操作进行了比较好的封装,针对Blob类型字段的操作也不例外。但网上大部分能找到的hibernate操作Blob的例程都是基于hibernate2版本的,同时在实际操作中我发现针对不同的数据库,可以有不同的操作方法。下面将hibernate3操作oracle的Blob字段进行一个介绍。          用JDBC操作Blob最

759

Hibernate 操作Blob Clob

Photo.java import java.sql.Blob; import java.sql.Clob; import java.util.Date; /** * @author IBM 这是一个用于测试Hibernate大对象操作的PO * * 这是一个测试POJO, 属性有多种类型 */ public class Photo { pri...

大阳阳 65

hibernate操作mysql的blob数据

package hibernate; import java.sql.Blob; public class Blobtest  implements java.io.Serializable {      private long id;      private Blob image;     public Blobtest() {     }     publ

JAVA2010CZP的专栏 3881
上一篇: JDBC+Hibernate将Blob数据写入Oracle
下一篇: 在spring中应用drools
tkxing
博客等级 码龄19年 1粉丝 57原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值