数据库大数据存储类型演示
来源:互联网 发布:鹊桥 淘宝客 区别 编辑:程序博客网 时间:2024/05/10 12:37
import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.BufferedReader;import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.Statement;import org.junit.Test;import cn.hncu.util.ConnFactory;public class BigDataDemo { @Test //向数据库写文本数据 public void testWriteText() throws Exception{ Connection con = ConnFactory.getConnection(); String sql = "insert into bigdata(note) values(?)"; PreparedStatement pst = con.prepareStatement(sql); InputStream in = BigDataDemo.class.getClassLoader().getResourceAsStream("JdbcDemo.abc"); pst.setAsciiStream(1, in); pst.executeUpdate(); con.close(); } @Test //从数据库读文本数据 public void testReadText() throws Exception{ Connection con = ConnFactory.getConnection(); String sql = "select * from bigdata where id= 1"; Statement st = con.createStatement(); ResultSet rs = st.executeQuery(sql); while(rs.next()){ InputStream in = rs.getAsciiStream(2); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line = ""; while((line=br.readLine())!=null){ System.out.println(line); } } } @Test //向数据库写图片 public void testWriteBlob() throws Exception{ Connection con = ConnFactory.getConnection(); String sql = "insert into bigdata(img) values(?)"; PreparedStatement pst = con.prepareStatement(sql); InputStream in = BigDataDemo.class.getClassLoader().getResourceAsStream("0.jpg"); pst.setBinaryStream(1, in); pst.executeUpdate(); con.close(); } @Test //从数据库读图片 public void testReadBlob() throws Exception{ Connection con = ConnFactory.getConnection(); Statement st = con.createStatement(); String sql = "select img from bigdata where id = 5"; ResultSet rs = st.executeQuery(sql); while(rs.next()){ BufferedInputStream bis = new BufferedInputStream(rs.getBinaryStream(1)); OutputStream out = new FileOutputStream(new File("D:/a/img.jpg")); BufferedOutputStream bos = new BufferedOutputStream(out); int len = 0; byte buf[] = new byte[512]; while((len = bis.read(buf))!=-1){ bos.write(buf, 0, len); } bis.close(); bos.close(); out.close(); } con.close(); }}
0 0
- 数据库大数据存储类型演示
- 大对象类型数据存储
- 数据库中存储json类型的数据
- 大数据在数据库中的存储
- 大数据存储和管理数据库系统
- 数据库大数据BLOB类型转换文本
- 大数据时代的 9 大Key-Value存储数据库
- 大数据时代的 9 大Key-Value存储数据库
- 大数据时代的 9 大Key-Value存储数据库
- 大数据时代的 9 大Key-Value存储数据库
- 大数据时代的 9 大Key-Value存储数据库
- 对特种类型数据在数据库中的读取和存储
- 收藏一个关于数据库存储BLOB类型数据的方法
- 使用dbutils工具向数据库中存储大数据
- Redis数据库存储类型
- 数据库存储大对象
- C51-数据存储类型
- C++ 数据存储类型
- Cocos2dx 小技巧 Label的换行(js实现)
- js时间戳
- Flume采集数据到HDFS时,文件中有乱码
- 前端开发人员必须了解的七大技能图谱
- 服装商城APP软件开发方案
- 数据库大数据存储类型演示
- linux常用命令的英文单词缩写
- Healthy Holsteins_usaco2.1.4_codevs2044_dfs
- Android 保证Service不被杀掉(broadcast+system/app)
- linux自定义shell(bash)命令
- $(document).ready()与$(window).load()的区别
- PHP 利用SMPT服务器发送邮件 无需自己配置服务器
- sdut oj2128 树结构练习——排序二叉树的中序遍历
- 不让bat文件运行命令结束后cmd窗口自动关闭