Hibernate对大数据类型的存储和查询

方式一:使用byte[] 和 char[] 映射blob 和clob类型
<p><span style="font-weight: normal;">import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Entity;
@Entity
@Table(name="bigdata1")
public class BigData1 {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private int id;
	@Lob
	@Column(name="icon")
	private byte[] icon;
	@Lob
	@Column
	private char[] msg;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public byte[] getIcon() {
		return icon;
	}
	public void setIcon(byte[] icon) {
		this.icon = icon;
	}
	public char[] getMsg() {
		return msg;
	}
	public void setMsg(char[] msg) {
		this.msg = msg;
	}
	public BigData1(int id, byte[] icon, char[] msg) {
		super();
		this.id = id;
		this.icon = icon;
		this.msg = msg;
	}
	public BigData1() {
		super();
	}
	
}</span>
</p>
二:使用sql包下面的 Blob了 Clob类
<span style="font-weight: normal;">import java.sql.Blob;
import java.sql.Clob;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Entity;


@Entity
@Table(name="bigdata2")
public class BigData2 {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private int id;
	@Lob
	@Column(name="icon",nullable=false)
	private Blob icon;
	@Lob
	@Column(nullable=false)
	private Clob msg;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	
	public BigData2(int id, Blob icon, Clob msg) {
		super();
		this.id = id;
		this.icon = icon;
		this.msg = msg;
	}
	public Blob getIcon() {
		return icon;
	}
	public void setIcon(Blob icon) {
		this.icon = icon;
	}
	public Clob getMsg() {
		return msg;
	}
	public void setMsg(Clob msg) {
		this.msg = msg;
	}
	public BigData2() {
		super();
	}
	
}</span>

3:测试代码
<span style="font-weight: normal;">import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.Reader;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistryBuilder;

public class BigData1Test {
	private static Configuration configuration = null;
	private static SessionFactory sessionFactory = null;
	private static org.hibernate.service.ServiceRegistry serviceRegistry = null;
	private static Session session = null;
	static{
		configuration = new Configuration();	
	//	configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost/test?characterEncoding=utf-8");
	
		configuration.configure();
		serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
		sessionFactory = configuration.buildSessionFactory(serviceRegistry);
		session = sessionFactory.getCurrentSession();
		
	}
	public static void main(String[] args) throws Exception {
		session.beginTransaction();
		
		
		
		session.getTransaction().commit();
		
	}
	
	
	/**
	 * 对BigData1.class 的存取
	 * @throws Exception
	 */
	public static void save1() throws Exception{
		BigData1 bd = new BigData1();
		File f = new File("c:/a.jpg");
		FileInputStream fis = new FileInputStream(f);
		byte[] b = new byte[fis.available()];  
		fis.read(b);
		bd.setIcon(b);
		BufferedReader br = new BufferedReader(new FileReader(new File("c:/b.txt")));
		StringBuffer sb = new StringBuffer();
		char[] c = new char[512];
		int i = 0;
		while((i = br.read(c)) != -1){
			sb.append(new String(c, 0, i));
		}
		bd.setMsg(sb.toString().toCharArray());
		session.save(bd);
	}
	public static void get1() throws Exception{
		BigData1 bd = (BigData1) session.get(BigData1.class, 11);
		FileOutputStream fos = new FileOutputStream(new File("c:/a_a.jpg"));
		fos.write(bd.getIcon());
		fos.flush();
		fos.close();
		BufferedWriter bw = new BufferedWriter(new FileWriter(new File("c:/a_a.txt")));
	
		bw.write(new String(bd.getMsg()));
		bw.flush();
		bw.close();
		
	}
	
	
	/**
	 * 是对 BigData2.class 的存取
	 * @throws Exception
	 */
	public static void save2() throws Exception{
		BigData2 bd = new BigData2();
		FileInputStream fis = new FileInputStream(new File("c:/a.jpg"));
		bd.setIcon(Hibernate.getLobCreator(session).createBlob(fis,fis.available()));
		BufferedReader br = new BufferedReader(new FileReader(new File("c:/a.txt")));
		StringBuffer sb = new StringBuffer();
		char[] c = new char[512];
		int i = 0;
		while((i = br.read(c)) != -1){
			sb.append(new String(c, 0, i));
		}
		bd.setMsg(Hibernate.getLobCreator(session).createClob(sb.toString()));
		session.save(bd);
		
	}
	public static void get2() throws Exception{
		BigData2 bd = (BigData2) session.get(BigData2.class, 5);
		FileOutputStream fos = new FileOutputStream(new File("c:/a_a.jpg"));
		byte[] b = new byte[1024];
		InputStream is = bd.getIcon().getBinaryStream();
		int len = 0;
		while((len = is.read(b)) != -1){
			fos.write(b, 0, len);
		}
		fos.flush();
		fos.close();
		is.close();
		BufferedWriter bw = new BufferedWriter(new FileWriter(new File("c:/a_a.txt")));
		Reader r = bd.getMsg().getCharacterStream();
		char[] c = new char[512];
		
		while((len = r.read(c)) != -1){
			bw.write(c, 0, len);
		}
		bw.flush();
		bw.close();
		r.close();
	}
	
}</span>
Mysql中上传文件过大:Mysql中默认为1M ,在my.ini配置文件中修改或者加入 max_allowed_packet=4M 此配置
oracle中保存也可能会出现错误,我这里是jar包问题,可以在oracle安装目录 product\11.2.0\dbhome_1\jdbc\lib 这里面寻找jar包(还有就是你oracle表空间大小4M,你保存的文件数据超过了表空间大小也会保存,需要修改表空间大小)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 这是一个非常有挑战性和有意义的项目,需要一定的技术和专业知识才能完成。下面是一些可能涉及的技术和步骤: 1. 数据采集和存储:需要从各种数据源(比如人力资源管理系统、社交媒体等)获取数据,并将其存储到数据库中,可以使用Java中的JDBC或者ORM框架(比如Hibernate)来实现数据访问。 2. 数据处理和分析:需要对数据进行清洗、加工和分析,可以使用Java中的数据处理库(比如Apache Commons、Guava等),或者使用机器学习框架(比如TensorFlow)来进行数据挖掘和预测。 3. 大屏展示:需要使用Java的Web框架(比如SpringMVC、Struts2等)来开发Web应用程序,用于展示分析结果和提供交互功能。可以使用前端框架(比如Angular、React等)来构建动态大屏界面,实现数据可视化和交互。 4. 地图显示:可以使用地图API(比如百度地图、高德地图等)来显示地图,并结合数据展示人才分布、流动等信息。 5. 数据提交:可以使用表单技术(比如HTML表单、Bootstrap表单等)来收集用户数据,并通过Java的Servlet或者SpringMVC的Controller来处理数据提交请求。 6. 安全和性能优化:需要对应用程序进行安全和性能优化,比如输入数据验证、SQL注入防护、缓存技术等。 以上是一个简单的项目架构和实现步骤,具体实现中还需要根据具体需求和场景来调整和完善。 ### 回答2: 使用Java和Web进行软件开发,可以实现人力大数据的大屏展示。通过对各种类型人才的统计分析,可以实现预测、预警等各项功能。用户只需要通过一张表格提交数据给系统即可实现动态展示,并且还可以在地图上进行显示。 首先,使用Java语言进行软件开发,搭建后端系统。可以使用Spring框架来实现系统的基本功能,包括用户登录、权限管理、数据处理等。通过Spring MVC可以搭建Web应用,方便用户的访问和使用。 然后,使用Java的数据处理和分析工具,如Apache Spark,对各种类型人才的数据进行统计分析。可以使用Spark的分布式计算和内存计算功能,快速处理大规模数据集,并提取出有用的信息。 在Web前端的开发中,可以使用HTML、CSS和JavaScript等技术,搭建用户界面。通过JavaScript的图表库,如Echarts或Highcharts,可以绘制各种统计图表,如柱状图、饼图等,方便用户对人力大数据进行可视化分析。 通过与数据库的交互,将用户提交的数据存储起来,并在需要时取出进行统计分析和展示。可以使用MySQL或者其他关系型数据库来存储数据。 对于地图显示功能,可以使用JavaScript地图库,如百度地图、高德地图等,将人力大数据在地图上进行显示。用户可以通过地图来查看各种人才的分布情况,从而更好地进行人才资源的管理和决策。 最后,通过使用Java和Web进行软件开发,结合人力大数据的统计分析,可以实现预测、预警等功能,帮助企业更好地进行人才管理和人力资源规划。用户只需通过提交数据给系统,就能够实现动态的大屏展示,并且可以通过地图来直观地展示人才分布情况,提供更为全面和准确的数据支持。 ### 回答3: 使用JAVA和WEB进行软件开发,可以实现人力大数据的大屏展示,并通过对各种类型人才的统计分析,实现预测、预警等各项功能。通过收集和整理大量人力数据,并将其存储于数据库中,我们可以通过JAVA编程语言在WEB平台上进行相关数据处理和展示。 首先,我们可以设计数据库模型来存储各种类型人才的相关信息,例如人才的基本信息、技能特长、岗位需求、薪资水平等。利用JAVA编程语言,我们可以编写数据处理和分析算法,通过对人才数据进行统计分析,实现预测和预警功能。例如,我们可以使用回归分析等方法,预测不同类型人才的需求量和市场趋势,通过提前发出预警,帮助企业做好人员招募和培养计划。 其次,我们可以使用WEB技术来实现动态展示功能。通过使用HTML、CSS和JavaScript等前端开发技术,我们可以设计用户友好的网页界面,展示人力大数据的统计结果。同时,我们可以利用Java Servlet和JavaServer Pages(JSP)等后端技术,与前端界面进行数据交互和展示。用户可以通过网页表单提交人才相关信息,例如搜索条件、需求岗位、人才类型等,并实时获得展示结果。在展示结果中,我们可以使用地图API来显示人才地理分布情况,帮助企业快速了解各地区的人才资源分布情况。 综上所述,通过使用JAVA和WEB进行软件开发,我们可以实现人力大数据的大屏展示,通过统计分析实现预测、预警等功能,并通过地图显示功能帮助企业了解人才资源的地理分布情况。这样的软件系统可以极大地提升企业在人才招募、培养和决策方面的效率和准确性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值