javaweb基础(34)_jdbc处理mysql大数据
一、基本概念
大数据也称之为LOB(Large Objects),LOB又分为:clob和blob,clob用于存储大文本,blob用于存储二进制数据,例如图像、声音、二进制文等。
在实际开发中,有时是需要用程序把大文本或二进制数据直接保存到数据库中进行储存的。
对MySQL而言只有blob,而没有clob,mysql存储大文本采用的是Text,Text和blob分别又分为:
TINYTEXT、TEXT、MEDIUMTEXT和LONGTEXT
TINYBLOB、BLOB、MEDIUMBLOB和LONGBLOB
二、搭建测试环境
2.1、搭建的测试项目架构
如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUcAAAEcCAIAAADbYuEIAAAgAElEQVR4nO2dbXAcxZ3/5w11L88vUpXjxVV8OZKjQv2DLcuq3Nb9seuugp3cA7qrc2wnNhKVZA6qclXCIRU/4GjlJxRDLhOwg8GxtBBsCyFTe3EY5D+YXYfYkUGYBQLZv/aE5FhgPbP4iTW20/dinrpnumdnV7vamd7vp37l2pnp7uke91fdMzv9XYUAUAxdVRRFUfVa1wMEQ6l1BQAAFQaqBkA2oGoAZKNMVV+/8afjb8/sefHsjr5hBKKqsefFs8ffnrl+40+V7foSU6aqfz04+cKZ6bHZaxcKBIGoaozNXnvhzPSvBycr2/UlpkxV706+P3P5xswVMn1ZGCMjqfbu7mXdqfbu7pGRlE9KBMInZq6Qmcs3diffr2zXl5gyVb2jb/jjApm6JIyRkdSyVKollUqn04nEM8u6UyMjKZ/0CIRPfFwgO/qGK9v1JaZ8Vec/IRMXnXjryCY7Ji6S9lSqpTvVnepOjbSnUt0t7amW9m46fWgit71JWf98zatR0XheVZq0gZpXo3KR/wSqLoHyVf3RJ2T8ghmZvk300UzfxmXdqXQ6nUq1tHcva+9etqx92bKWbjs9E32q0qQNcA8FjkP3KMo9ur050Bmjy3RtspHb1qSs7wt2IqequW1NCoV6yFUZG/d59fX2IarC44I0QSs2l0v6ptbIOZ1dh9i2N9mSubV6U2tUlMbOnF/2Iieir6E7+0dQdSmUr+rZK2Rvx4/3d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C33OQtuKmGuoDSE5wyzPG6yICZlXkbrqmtxTAubtx1gNak+1VE0IOX/+fEdHx+zsLDfZr9sbCqMJO45suN0nOPlNGdtqNj8wfoQcb7DidkUumxJ21LWSifZD1SAEVEvVMzMz/mP1kQ23FbKaEUc23F4Y3ceN8UwnX9X2zNtSF2e7uJMRV42Urjnq9ToTU/uhahACqqLqqampovfVB793SyHbWch2Htlwu/HBG2JJE2I9JWOmwe5tjzdYMBMy6sbaM9Mush+qBrWnZs/Au1r+spDZeGTD7YVMnBv+kibEnGNTEnJvC233A5qQOeN1wKdl1DnxtAzUjpp9X/3Tf7v5yIbbC5mN3CguaQCAgFq+W9al/o1P1LBiAESaensPHAD5gaoBkA2oGgDZgKoBkI3/BaO1bYEY9bs4AAAAAElFTkSuQmCC" alt="" />
2.2、编写db.properties配置文件
1 driver=com.mysql.jdbc.Driver
2 url=jdbc:mysql://localhost:3306/jdbcStudy
3 username=root
4 password=XDP
2.3、编写JdbcUtils工具类
1 package me.gacl.utils;
2
3 import java.io.InputStream;
4 import java.sql.Connection;
5 import java.sql.DriverManager;
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8 import java.sql.Statement;
9 import java.util.Properties;
10
11 public class JdbcUtils {
12
13 private static String driver = null;
14 private static String url = null;
15 private static String username = null;
16 private static String password = null;
17
18 static{
19 try{
20 //读取db.properties文件中的数据库连接信息
21 InputStream in = JdbcUtils.class.getClassLoader().getResourceAsStream("db.properties");
22 Properties prop = new Properties();
23 prop.load(in);
24
25 //获取数据库连接驱动
26 driver = prop.getProperty("driver");
27 //获取数据库连接URL地址
28 url = prop.getProperty("url");
29 //获取数据库连接用户名
30 username = prop.getProperty("username");
31 //获取数据库连接密码
32 password = prop.getProperty("password");
33
34 //加载数据库驱动
35 Class.forName(driver);
36
37 }catch (Exception e) {
38 throw new ExceptionInInitializerError(e);
39 }
40 }
41
42 /**
43 * @Method: getConnection
44 * @Description: 获取数据库连接对象
45 * @Anthor:孤傲苍狼
46 *
47 * @return Connection数据库连接对象
48 * @throws SQLException
49 */
50 public static Connection getConnection() throws SQLException{
51 return DriverManager.getConnection(url, username,password);
52 }
53
54 /**
55 * @Method: release
56 * @Description: 释放资源,
57 * 要释放的资源包括Connection数据库连接对象,负责执行SQL命令的Statement对象,存储查询结果的ResultSet对象
58 * @Anthor:孤傲苍狼
59 *
60 * @param conn
61 * @param st
62 * @param rs
63 */
64 public static void release(Connection conn,Statement st,ResultSet rs){
65 if(rs!=null){
66 try{
67 //关闭存储查询结果的ResultSet对象
68 rs.close();
69 }catch (Exception e) {
70 e.printStackTrace();
71 }
72 rs = null;
73 }
74 if(st!=null){
75 try{
76 //关闭负责执行SQL命令的Statement对象
77 st.close();
78 }catch (Exception e) {
79 e.printStackTrace();
80 }
81 }
82
83 if(conn!=null){
84 try{
85 //关闭Connection数据库连接对象
86 conn.close();
87 }catch (Exception e) {
88 e.printStackTrace();
89 }
90 }
91 }
92 }
三、使用JDBC处理MySQL的大文本
对于MySQL中的Text类型,可调用如下方法设置
1 PreparedStatement.setCharacterStream(index, reader, length);//注意length长度须设置,并且设置为int型
对MySQL中的Text类型,可调用如下方法获取
1 reader = resultSet. getCharacterStream(String columnLabel);2 string s = resultSet.getString(String columnLabel);
3.1、 测试范例
1、编写SQL测试脚本
1 create database jdbcstudy;
2 use jdbcstudy;
3 create table testclob
4 (
5 id int primary key auto_increment,
6 resume text
7 );
2、编写测试代码如下:
1 package me.gacl.demo;
2
3 import java.io.File;
4 import java.io.FileReader;
5 import java.io.FileWriter;
6 import java.io.Reader;
7 import java.sql.Connection;
8 import java.sql.PreparedStatement;
9 import java.sql.ResultSet;
10 import me.gacl.utils.JdbcUtils;
11 import org.junit.Test;
12
13 /**
14 * @ClassName: JdbcOperaClob
15 * @Description: 使用JDBC操作MySQL的大文本
16 * @author: 孤傲苍狼
17 * @date: 2014-9-19 下午10:10:04
18 *
19 */
20 public class JdbcOperaClob {
21
22 /**
23 * @Method: add
24 * @Description:向数据库中插入大文本数据
25 * @Anthor:孤傲苍狼
26 *
27 */
28 @Test
29 public void add(){
30 Connection conn = null;
31 PreparedStatement st = null;
32 ResultSet rs = null;
33 Reader reader = null;
34 try{
35 conn = JdbcUtils.getConnection();
36 String sql = "insert into testclob(resume) values(?)";
37 st = conn.prepareStatement(sql);
38 //这种方式获取的路径,其中的空格会被使用“%20”代替
39 String path = JdbcOperaClob.class.getClassLoader().getResource("data.txt").getPath();
40 //将“%20”替换回空格
41 path = path.replaceAll("%20", " ");
42 File file = new File(path);
43 reader = new FileReader(file);
44 st.setCharacterStream(1, reader,(int) file.length());
45 int num = st.executeUpdate();
46 if(num>0){
47 System.out.println("插入成功!!");
48 }
49 //关闭流
50 reader.close();
51 }catch (Exception e) {
52 e.printStackTrace();
53 }finally{
54 JdbcUtils.release(conn, st, rs);
55 }
56 }
57
58 /**
59 * @Method: read
60 * @Description: 读取数据库中的大文本数据
61 * @Anthor:孤傲苍狼
62 *
63 */
64 @Test
65 public void read(){
66 Connection conn = null;
67 PreparedStatement st = null;
68 ResultSet rs = null;
69 try{
70 conn = JdbcUtils.getConnection();
71 String sql = "select resume from testclob where id=2";
72 st = conn.prepareStatement(sql);
73 rs = st.executeQuery();
74
75 String contentStr ="";
76 String content = "";
77 if(rs.next()){
78 //使用resultSet.getString("字段名")获取大文本数据的内容
79 content = rs.getString("resume");
80 //使用resultSet.getCharacterStream("字段名")获取大文本数据的内容
81 Reader reader = rs.getCharacterStream("resume");
82 char buffer[] = new char[1024];
83 int len = 0;
84 FileWriter out = new FileWriter("D:\\1.txt");
85 while((len=reader.read(buffer))>0){
86 contentStr += new String(buffer);
87 out.write(buffer, 0, len);
88 }
89 out.close();
90 reader.close();
91 }
92 System.out.println(content);
93 System.out.println("-----------------------------------------------");
94 System.out.println(contentStr);
95 }catch (Exception e) {
96 e.printStackTrace();
97 }finally{
98 JdbcUtils.release(conn, st, rs);
99 }
100 }
101 }
四、使用JDBC处理MySQL的二进制数据
对于MySQL中的BLOB类型,可调用如下方法设置:
1 PreparedStatement. setBinaryStream(i, inputStream, length);
对MySQL中的BLOB类型,可调用如下方法获取:
1 InputStream in = resultSet.getBinaryStream(String columnLabel);
2 InputStream in = resultSet.getBlob(String columnLabel).getBinaryStream();
4.1、 测试范例
1、编写SQL测试脚本
1 create table testblob
2 (
3 id int primary key auto_increment,
4 image longblob
5 );
2、编写测试代码如下:
1 package me.gacl.demo;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileOutputStream;
6 import java.io.InputStream;
7 import java.sql.Connection;
8 import java.sql.PreparedStatement;
9 import java.sql.ResultSet;
10 import me.gacl.utils.JdbcUtils;
11 import org.junit.Test;
12
13 /**
14 * @ClassName: JdbcOperaClob
15 * @Description: 使用JDBC操作MySQL的二进制数据(例如图像、声音、二进制文)
16 * @author: 孤傲苍狼
17 * @date: 2014-9-19 下午10:10:04
18 *
19 */
20 public class JdbcOperaBlob {
21
22 /**
23 * @Method: add
24 * @Description:向数据库中插入二进制数据
25 * @Anthor:孤傲苍狼
26 *
27 */
28 @Test
29 public void add(){
30 Connection conn = null;
31 PreparedStatement st = null;
32 ResultSet rs = null;
33 try{
34 conn = JdbcUtils.getConnection();
35 String sql = "insert into testblob(image) values(?)";
36 st = conn.prepareStatement(sql);
37 //这种方式获取的路径,其中的空格会被使用“%20”代替
38 String path = JdbcOperaBlob.class.getClassLoader().getResource("01.jpg").getPath();
39 //将“%20”替换会空格
40 path = path.replaceAll("%20", " ");
41 File file = new File(path);
42 FileInputStream fis = new FileInputStream(file);//生成的流
43 st.setBinaryStream(1, fis,(int) file.length());
44 int num = st.executeUpdate();
45 if(num>0){
46 System.out.println("插入成功!!");
47 }
48 fis.close();
49 }catch (Exception e) {
50 e.printStackTrace();
51 }finally{
52 JdbcUtils.release(conn, st, rs);
53 }
54 }
55
56 /**
57 * @Method: read
58 * @Description: 读取数据库中的二进制数据
59 * @Anthor:孤傲苍狼
60 *
61 */
62 @Test
63 public void read() {
64 Connection conn = null;
65 PreparedStatement st = null;
66 ResultSet rs = null;
67 try {
68 conn = JdbcUtils.getConnection();
69 String sql = "select image from testblob where id=?";
70 st = conn.prepareStatement(sql);
71 st.setInt(1, 1);
72 rs = st.executeQuery();
73 if (rs.next()) {
74 //InputStream in = rs.getBlob("image").getBinaryStream();//这种方法也可以
75 InputStream in = rs.getBinaryStream("image");
76 int len = 0;
77 byte buffer[] = new byte[1024];
78
79 FileOutputStream out = new FileOutputStream("D:\\1.jpg");
80 while ((len = in.read(buffer)) > 0) {
81 out.write(buffer, 0, len);
82 }
83 in.close();
84 out.close();
85 }
86 } catch (Exception e) {
87 e.printStackTrace();
88 } finally {
89 JdbcUtils.release(conn, st, rs);
90 }
91 }
92 }
关于使用JDBC处理MySQL大数据的内容就总结这么多!
javaweb基础(34)_jdbc处理mysql大数据的更多相关文章
- javaweb基础(35)_jdbc处理oracl大数据
一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...
- javaweb学习总结(三十四)——使用JDBC处理MySQL大数据
一.基本概念 大数据也称之为LOB(Large Objects),LOB又分为:clob和blob,clob用于存储大文本,blob用于存储二进制数据,例如图像.声音.二进制文等. 在实际开发中,有时 ...
- javaweb(三十四)——使用JDBC处理MySQL大数据
一.基本概念 大数据也称之为LOB(Large Objects),LOB又分为:clob和blob,clob用于存储大文本,blob用于存储二进制数据,例如图像.声音.二进制文等. 在实际开发中,有时 ...
- MySQL 大数据量快速插入方法和语句优化
MySQL大数据量快速插入方法和语句优化是本文我们主要要介绍的内容,接下来我们就来一一介绍,希望能够让您有所收获! INSERT语句的速度 插入一个记录需要的时间由下列因素组成,其中的数字表示大约比例 ...
- Mysql学习总结(13)——使用JDBC处理MySQL大数据
一.基本概念 大数据也称之为LOB(Large Objects),LOB又分为:clob和blob,clob用于存储大文本,blob用于存储二进制数据,例如图像.声音.二进制文等. 在实际开发中,有时 ...
- MySQL大数据分页的优化思路和索引延迟关联
之前上次在部门的分享会上,听了关于MySQL大数据的分页,即怎样使用limit offset,N来进行大数据的分页,现在做一个记录: 首先我们知道,limit offset,N的时候,MySQL的查询 ...
- MySQL大数据量分页查询
mysql大数据量使用limit分页,随着页码的增大,查询效率越低下. 测试实验 1. 直接用limit start, count分页语句, 也是我程序中用的方法: select * from p ...
- 【1】MySQL大数据量分页查询方法及其优化
---方法1: 直接使用数据库提供的SQL语句---语句样式: MySQL中,可用如下方法: SELECT * FROM 表名称 LIMIT M,N---适应场景: 适用于数据量较少的情况(元组百/千 ...
- mysql大数据量下的分页
mysql大数据量使用limit分页,随着页码的增大,查询效率越低下. 测试实验 1. 直接用limit start, count分页语句, 也是我程序中用的方法: select * from p ...
随机推荐
- Redis数据类型,持久化,回收策略——(Redis缓存第一章)
缓存:第一种是内存缓存 比如Map(简单的数据结构),以及EH Cache(Java第三方库),第二种是缓存组件比如Memached,Redis:Redis(remote dictionary ser ...
- Webpack打包时警告 - Critical dependency: the request of a dependency is an expression
关于解决 [Webpack] Critical dependency: the request of a dependency is an expression ------------------- ...
- rem字体在rem盒子里面不一样,或者不同的行解决
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 再谈布局,栅栏式自适应布局的学习和实现(calc自适应布局)
布局真的很重要.一个不好的布局后期会有很多很多的bug,就像是建房子的地基一样. 首先,再一次地圣杯布局的学习,来源于该教程: http://www.jianshu.com/p/f9bcddb0e8b ...
- 移动端APP第一次登录和自动登录流程
App登陆保存数据流程App因为要实现自动登陆功能,所以必然要保存一些凭据,所以比较复杂. App登陆要实现的功能: 密码不会明文存储,并且不能反编绎解密: 在服务器端可以控制App端的登陆有效性,防 ...
- @GeneratorValue与@GenericGenerator注解使用心得
参考博主们的 http://blog.csdn.net/tianxiezuomaikong/article/details/64930151
- 非局部均值去噪(NL-means)
非局部均值(NL-means)是近年来提出的一项新型的去噪技术.该方法充分利用了图像中的冗余信息,在去噪的同时能最大程度地保持图像的细节特征.基本思想是:当前像素的估计值由图像中与它具有相似邻域结构的 ...
- Java面向对象_Object类
Object类 是类层次结构的根类,每个类都是用Object类作为超类,所有对象(包括数组)都实现这个类的方法.所有类都是Object类的子类. 下面先说两个方法toString()和equals(O ...
- MongoDB Linux 安装配置 后台运行
介绍安装的文档很多,可以参考这篇: http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/ 安装完后你可能会碰到的2个问题. ...
- Java hibernate 遇到的问题:could not read a hi value
问题: 解决办法:在网上看到一篇文章说是把数据库实体类的注解@GeneratedValue改成@GeneratedValue(strategy = GenerationType.IDENTITY) , ...