1. 往mysql中读写字符文本

public class Demo1 {

	/* 创建数据库
create database LOBTest;
use LOBTest;
create table testclob
(
id int primary key auto_increment,
resume text
); */ @Test
public void add() {
Connection conn = null;
PreparedStatement st = null;
ResultSet rs = null;
try
{
conn = JdbcUtils.getConnection();
String sql = "insert into testclob(resume) values(?)";
st = conn.prepareStatement(sql);
String path = Demo1.class.getClassLoader().getResource("db.properties").getPath();
File file = new File(path);
FileReader fr = new FileReader(file);
st.setCharacterStream(1, fr, file.length());
int num = st.executeUpdate();
if(num > 0)
System.out.println("插入成功!!");
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
JdbcUtils.release(conn, st, rs);
}
} @Test
public void read()
{
Connection conn = null;
PreparedStatement st = null;
ResultSet rs = null;
try
{
conn = JdbcUtils.getConnection();
String sql = "select resume from testclob where id = ?";
st = conn.prepareStatement(sql);
st.setInt(1, 2);
rs = st.executeQuery();
if(rs.next())
{
Reader reader = rs.getCharacterStream("resume");
FileWriter fw = new FileWriter("write.txt");
char[] buffer = new char[1024];
int len = 0;
while( (len=reader.read(buffer)) > 0)
{
fw.write(buffer, 0, len);
}
fw.close();
reader.close();
} }
catch (Exception e)
{
e.printStackTrace();
}
finally
{
JdbcUtils.release(conn, st, rs);
}
} }

2. 往mysql中读写二进制文件

public class Demo2 {

	/*
create table testblob
(
id int primary key auto_increment,
image blob
);
*/ @Test
public void add()
{
Connection conn = null;
PreparedStatement st = null;
ResultSet rs = null;
try
{
conn = JdbcUtils.getConnection();
String sql = "insert into testblob(image) values(?)";
st = conn.prepareStatement(sql); String path = Demo1.class.getClassLoader().getResource("1.JPG").getPath();
File file = new File(path);
FileInputStream sf = new FileInputStream(file);
st.setBinaryStream(1, sf, file.length());
int num = st.executeUpdate();
if(num > 0)
System.out.println("插入成功!!");
sf.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
JdbcUtils.release(conn, st, rs);
}
} @Test
public void read()
{
Connection conn = null;
PreparedStatement st = null;
ResultSet rs = null;
try
{
conn = JdbcUtils.getConnection();
String sql = "select image from testblob where id = ?";
st = conn.prepareStatement(sql);
st.setInt(1, 1);
rs = st.executeQuery();
if(rs.next())
{
InputStream is = rs.getBinaryStream("image");
byte[] buffer = new byte[1024];
int len = 0;
FileOutputStream fos = new FileOutputStream("1_back.JPG");
while( (len=is.read(buffer))>0 )
{
fos.write(buffer, 0, len);
}
fos.close();
is.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
JdbcUtils.release(conn, st, rs);
}
} }

Java -- JDBC mysql读写大数据,文本 和 二进制文件的更多相关文章

  1. 使用JDBC处理Oracle大数据

    一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...

  2. 利用jdbc处理oracle大数据---大文件和二进制文件

    一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...

  3. JavaWeb学习总结(三十五)——使用JDBC处理Oracle大数据

    一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...

  4. JavaWeb(三十五)——使用JDBC处理Oracle大数据

    一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...

  5. java 跨数据库导入大数据

    java 跨数据库导入大数据 /** * java程序跨服务器跨数据库批量导入导出百万级数据 * @param args * @throws Exception */ public static vo ...

  6. C#大数据文本高效去重

    C#大数据文本高效去重 转载请注明出处 http://www.cnblogs.com/Huerye/ TextReader reader = File.OpenText(@"C:\Users ...

  7. mysql处理大数据量的查询速度究竟有多快和能优化到什么程度

    mysql处理大数据量的查询速度究竟有多快和能优化到什么程度 深圳-ftx(1433725026) 18:10:49  mysql有没有排名函数啊 横瓜(601069289) 18:13:06  无 ...

  8. 黑马基础阶段测试题:创建一个存储字符串的集合list,向list中添加以下字符串:”C++”、”Java”、” Python”、”大数据与云计算”。遍历集合,将长度小于5的字符串从集合中删除,删除成功后,打印集合中的所有元素

    package com.swift; import java.util.ArrayList; import java.util.List; import java.util.ListIterator; ...

  9. mysql的大数据量的查询

    mysql的大数据量查询分页应该用where 条件进行分页,limit 100000,100,mysql先查询100100数据量,查询完以后,将 这些100000数据量屏蔽去掉,用100的量,但是如果 ...

随机推荐

  1. poj1742

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 33998   Accepted: 11554 Descripti ...

  2. influxDB聚合类函数

    1)count()函数 返回一个(field)字段中的非空值的数量. SELECT COUNT(<field_key>) FROM <measurement_name> [WH ...

  3. Redis 持久化机制

    1.背景 之前在使用redis 时候,没有过多的考虑持久化! 但是这样即使你用了redis 也是徒劳,表面上你是用上了redis 进行缓存数据,感觉已经给自己的架构添加了一个道QPS 防护墙! 哈哈, ...

  4. Springboot 1.5.x版本上读取自定义配置文件问题

    原来的解决方案: 现在1.5.x以后取消了location地址 1.5以后解决方案:

  5. js split 的用法和定义 js split分割字符串成数组的实例代码

    关于js split的用法,我们经常用来将字符串分割为数组方便后续操作,今天写一段广告判断代码的时候,竟然忘了split的用法了,特整理下,方便需要的朋友, 关于js split的用法其它也不多说什么 ...

  6. style="display:{{searchInput==='' ? 'none':'block'}} "

    当用户没有有效输入时,是否显示提交按钮 style="display:{{searchInput==='' ? 'none':'block'}} "

  7. Linux Debian 如何部署 Qt?

    Linux Debian 如何部署 Qt? 在这里以 HelloWorld 为例 目录结构如下: . ├── HelloWorld ├── HelloWorld.sh ├── imageformats ...

  8. 一、Nuxt简介

    1.Nuxt是什么    Nuxt.js是基于vue的服务器端渲染框架,常用来做SSR(服务器端渲染)   2.为什么用Nuxt    Vue开发的SPA(单页应用)不利于搜索引擎的SEO优化   3 ...

  9. Linux用户相关文件之用户信息文件

    1.文件地址: /etc/pssswd -rw-r--r--. 1 root root 936 10月 6 12:50 /etc/passwd 2.文件内容: xiaol_1:x:501:501::/ ...

  10. make menuconfig 时出现 mixed implicit and normal rules: deprecated syntax

    這是 make 的版本問題!不清楚為何要這樣限制? 將此行          config %config: scripts_basic outputmakefile FORCE改成          ...