java 读取clob,blob转换为字符串
来源:互联网 发布:vba和vb的区别 编辑:程序博客网 时间:2024/06/08 21:28
java 读取clob,blob转换为字符串
* 读取oracleCLOB字段内容
* @param conn
* @return
*/
public static String readCLOB(Connection conn) {
String sql = "select 大字段1,大字段2 from 印章基本信息_char_ccbb where yzbm='2'";
String content = "";
try {
conn.setAutoCommit(false);
PreparedStatement ps1 = conn.prepareStatement(sql);
ResultSet rs1 = ps1.executeQuery();
while (rs1.next()) {
oracle.sql.CLOB clob = (oracle.sql.CLOB) rs1.getClob("大字段1");
BufferedReader in = new BufferedReader(clob
.getCharacterStream());
StringWriter out = new StringWriter();
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
content = out.toString();
System.out.println(content);// 输出CLOB内容
}
} catch (Exception e) {
e.printStackTrace();
}
return content;
}
/***
* 读取oracle的blob转换为字符串
* @param conn
* @return
*/
public static String ConvertBLOBtoString(Connection conn){
String newStr = ""; // 返回字符串
long BlobLength; // BLOB字段长度
byte[] bytes; // BLOB临时存储字节数组
int i = 1; // 循环变量
Statement st =null;
try {
st = conn.createStatement();
ResultSet rs = st
.executeQuery("select 大字段2 from 印章基本信息_char_ccbb where yzbm='2'");
while (rs.next()) {
BLOB blob = (BLOB) rs.getBlob("大字段2");
byte[] msgContent = blob.getBytes(); // BLOB转换为字节数组
BlobLength=blob.length(); //获取BLOB长度
if (msgContent == null || BlobLength==0) //如果为空,返回空值
{
return "";
}else{
while(i<BlobLength) //循环处理字符串转换,每次1024;Oracle字符串限制最大4k
{
bytes= blob.getBytes(i,1024) ;
i=i+1024;
newStr = newStr+new String(bytes,"gb2312") ;
}
}
}
System.out.println(newStr);
System.out.println(newStr.length());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(st!=null){
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return newStr;
}
- java 读取clob,blob转换为字符串
- java 读取Oracle的clob,blob转换为字符串
- clob 转换为blob
- C#读取Clob数据并转换为字符串
- java 读取oracle的blob/clob
- java读取oracle中Clob和Blob
- BLOB转换为CLOB的函数(oracle中执行)
- jdbc操作Blob和Clob字段与字符串的转换
- 数据库的CLOB/BLOB字段存为本地txt java
- JAVA中读取文件转换为字符串
- Blob,Clob类型转换String
- java中Clob转换为String
- JAVA 操作 Oracle Clob,Blob
- struts2前端页面读取Clob/BLOB
- ibatis 读取blob字段 CLOB字段
- struts2前端页面读取Clob BLOB
- Oracle中Blob转换成Clob
- CLOB转换为STRING
- YYCache的基本使用
- 【Python】Numpy简单入门
- 责任链模式的理解与实例
- C#开发Windows窗体应用程序的步骤
- 开发要搞清楚什么是并发,并行,串行,同步,异步?
- java 读取clob,blob转换为字符串
- UML大战需求分析-读书笔记
- java mongo $where
- 戴尔的下一代数据中心战略将会取得成功
- 博士生活与博客
- 自定义日志输出类log4j
- Windows编程一日一练(1)
- http错误代码含义
- 基于angular的退出全屏,全屏显示以及关闭系统