public class LobUtil {
private static final int BUFFER_SIZE = 4096;
private LobUtil() {
}
public static synchronized void writeBLOB(ResultSet rs, String fieldName,
byte[] buf) throws SQLException, IOException {
if (buf == null) {
return;
}
OutputStream os = null;
Blob b = rs.getBlob(fieldName);
if (b == null) {
throw new SQLException("刚刚插入或更新的BLOB指针为空!");
} else {
// if (Conn.isUseConnectionPool()){
// os =
// ((weblogic.jdbc.vendor.oracle.OracleThinBlob)b).getBinaryOutputStream();
// }
// else{
// os = ((oracle.sql.BLOB)b).getBinaryOutputStream();
// }
/**
* @todo 需要最终改造为通用数据库处理接口
*/
// <modify author="jdyao" time="2005-07-26">
try {
Method methodToInvoke = b.getClass().getMethod(
"getBinaryOutputStream", (Class[]) null);
os = (OutputStream) methodToInvoke.invoke(b, (Object[]) null);
} catch (Exception e) {
throw new SQLException(e.getMessage());
}
// os = ( (oracle.sql.BLOB) b).getBinaryOutputStream();
// </modify>
BufferedOutputStream bos = new BufferedOutputStream(os);
bos.write(buf);
bos.flush();
bos.close();
}
}
public static synchronized void writeBLOB(ResultSet rs, String fieldName,
InputStream in) throws SQLException, IOException {
if (in == null) {
return;
}
OutputStream os = null;
Blob b = rs.getBlob(fieldName);
if (b == null) {
throw new SQLException("刚刚插入或更新的BLOB指针为空!");
} else {
// if (Conn.isUseConnectionPool()){
// os =
// ((weblogic.jdbc.vendor.oracle.OracleThinBlob)b).getBinaryOutputStream();
// }
// else{
// os = ((oracle.sql.BLOB)b).getBinaryOutputStream();
// }
// <modify author="jdyao" time="2005-07-26">
try {
Method methodToInvoke = b.getClass().getMethod(
"getBinaryOutputStream", (Class[]) null);
os = (OutputStream) methodToInvoke.invoke(b, (Object[]) null);
} catch (Exception e) {
throw new SQLException(e.getMessage());
}
// os = ( (oracle.sql.BLOB) b).getBinaryOutputStream();
// </modify>
BufferedOutputStream bos = new BufferedOutputStream(os);
BufferedInputStream bis = new BufferedInputStream(in);
byte buf[] = new byte[BUFFER_SIZE];
int len = -1;
while ((len = bis.read(buf)) != -1) {
bos.write(buf, 0, len);
}
bis.close();
bos.flush();
bos.close();
}
}
public static synchronized void writeCLOB(ResultSet rs, String fieldName,
String buf) throws SQLException, IOException {
if (buf == null) {
return;
}
Writer wr = null;
Clob c = rs.getClob(fieldName);
if (c == null) {
throw new SQLException("刚刚插入或更新的CLOB指针为空!");
} else {
// <modify author="jdyao" time="2005-07-26">
try {
Method methodToInvoke = c.getClass().getMethod(
"getCharacterOutputStream", (Class[]) null);
wr = (Writer) methodToInvoke.invoke(c, (Object[]) null);
} catch (Exception e) {
throw new SQLException(e.getMessage());
}
// wr = ((oracle.sql.CLOB) c).getCharacterOutputStream();
// </modify>
BufferedWriter bw = new BufferedWriter(wr);
bw.write(buf);
bw.flush();
bw.close();
}
}
public static synchronized void writeCLOB(ResultSet rs, String fieldName,
InputStream in) throws SQLException, IOException {
if (in == null) {
return;
}
Writer wr = null;
Clob c = rs.getClob(fieldName);
if (c == null) {
throw new SQLException("刚刚插入或更新的CLOB指针为空!");
} else {
//<modify author="jdyao" time="2005-07-26">
try {
Method methodToInvoke = c.getClass().getMethod(
"getCharacterOutputStream", (Class[]) null);
wr = (Writer) methodToInvoke.invoke(c, (Object[]) null);
} catch (Exception e) {
throw new SQLException(e.getMessage());
}
//wr = ((oracle.sql.CLOB) c).getCharacterOutputStream();
//</modify>
BufferedWriter bw = new BufferedWriter(wr);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
char buf[] = new char[BUFFER_SIZE];
int len = -1;
while ( (len = br.read(buf)) != -1) {
bw.write(buf, 0, len);
}
br.close();
bw.flush();
bw.close();
}
}
}
详细解决方案
处置blob和clob的通用类
热度:278 发布时间:2012-11-25 11:44:31.0
相关解决方案
- JDBC 如何操作 CLOB
- 说下关于映射大对象(Blob,Clob)数据类型在Oracle中的处理....希望对大家有所 ...
- mysql 图片 blob 类型 如何 插入 excel 中
- php 读取 blob 乱码 blob中存的是普普通通文本,有中文
- 数据类型转换 BLOB 转 DataHandler解决方案
- MySQL blob 保存 word 乱码解决办法
- JDBC怎么读写B/CLOB
- 在做oracle数据库支持的时分,数据类型不一致: 应为 - 但却获得 CLOB
- oracle clob 字段 读取出来后空格仿佛少了很多
- oracle 10G 中 clob 显示有关问题
- ORA-00932: 数据类型不一致: 应为 - 但却获得 CLOB,该如何处理
- oracle 在pl/saql wm_concat 结果成 <clob>该如何处理
- oracle 在pl/saql wm_concat 结果成 <clob>解决思路
- 怎么 让 oracle 存储一个<BLOB 0 bytes> 数据 而不是NULL 当存储一个0 bytes 文件的时候
- clob 和varchar2的转换有关问题
- 关于CLOB ; BLOB 等大字处理!解决思路
- php 读取 blob 乱码 blob中存的是普普通通文本,有中文
- blob 是否可以作为基类型使用?该如何解决
- blob 是不是可以作为基类型使用
- 如何判断一个blob 变量里是否含有 另一个 blob 变量
- 怎么把 ‘192.168.10.34’这个IP地址赋值给一个 BLOB{2048}的变量lb_addr
- blob(布尔型)的赋值有关问题
- oracle.sql.CLOB cannot be cast to oracle.sql.CLOB转换异常
- 关于oracle clob 门类字段重建索引SQL及修复用户表空间索引空间的存储过程
- Round-tripping Blob to Array为数组值增加了48
- QuartzManager: Couldn‘t retrieve job because the BLOB couldn‘t be deserialized: null org.quartz.JobP
- react-native-document-picker一个适合react native打开本地文件,上传文件的组件;也可直接用react-native-fetch-blob
- mysql - blob 对应java 类 存储以及查询
- vue中使用文件流进行下载(new Blob)
- blob,base64互转;私有方法的测试;GSon的坑