JDBC对LOB的读写
在JDBC中提供了java.sql.Blob和java.sql.Clob两个类分别代表BLOB和CLOB数据
•BLOB(Binary Large Object):用于存储大量的二进制数据
•CLOB(Character Large Object):用于存储大量的文本数据
本文以MySQL为例,通过最基本的JDBC技术来处理大字段的插入、读取操作。
环境: MySQL5 JDK1.6
1)首先创建一张数据表:
create table stuinfo(
id int(11) not null auto_increment,
name varchar(20)default null,
content mediumtext ,
image blob,
primary key (id)
);
2)先数据库中插入BLOB和CLOB类型的数据
package cn.wjz.jdbc;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import cn.wjz.db.C