Clob类型转换为String
SQL CLOB 是内置类型,它将字符大对象存储为数据库表某一行中的一个列值,使用CHAR来存储数据,如XML文档。
如下是一个Clob转换为String的静态方法,可将其放在自己常用的工具类中,想直接用的话,自己稍作修改即可
public static String clobToStr(Clob clob) {
if(clob == null) {
return "";
}
StringBuffer strClob = new StringBuffer();
String str = "";
Reader read = null;
try{
reader = clob.getCharacterStream();
char[] buffer = new char[1024];
int length = 0;
while (length = reader.read(buffer, 0, 1024)) != -1) {
strClob.append(buffer, 0, length);
}
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try{
if (reader != null)
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
str = strClob.toString();
return str;
}
我在将数据导出成Excel时碰到的问题,需要导出的数据中有Clob格式只需将其Clob对象(若直接导出则显示的是地址)
这个工具挺好用的,放在这里,以后方便自己使用。(另:博客园的代码排版实在太丑了,以后还是在外面编辑好再粘贴进来比较好)
Clob类型转换为String的更多相关文章
- java Clob类型 转String
1.我的数据库是oracle11g 遇到取出来的字段是clob类型,但是所需要的是string类型,写一个转换函数就可以解决问题了. // Clob类型 转String public String C ...
- PHP 将json的int类型转换为string类型 解决php bigint转科学计数法的问题
/** * 将json的int类型转换为string类型 * @param $str * @param int $minLength 最小的转换位数,即只有大于等于这个长度的数字才会被转换为字符串 * ...
- Object类型转换为String类型
1. Object.toString() 1 obj.toString() 注意:必须保证Object不是null值,否则将抛出NullPointerException异常. 2. (String)O ...
- golang 学习之路 string转换为其他类型 其他类型转换为string
将其他值转换为string 一般常用fmt.Sprintf(格式,转换的值) // 使用fmt.Sprintf 转换所有的类型为string 使用 这是第一种 // 注意在sprintf使用中需要注意 ...
- linq中将int类型转换为string类型,toString()报错
今天同事在调试程序的时候,报了一个不寻常的错误, “LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式 ...
- Clob类型转化String类型
Clob clob=rs.getClob(列数); Clob clob=rs.getClob("列名");String content=clob.getSubString((lon ...
- C++中将string类型转换为int, float, double类型 主要通过以下几种方式:
C++中将string类型转换为int, float, double类型 主要通过以下几种方式: # 方法一: 使用stringstream stringstream在int或float类型转换为 ...
- c++ string类型转换为char *类型
string 是c++标准库里面其中一个,封装了对字符串的操作 把string转换为char* 有3中方法: 1.data 如: string str="abc"; char *p ...
- Java int类型与String类型互转
String类型转换为int类型 参考:https://blog.csdn.net/qq_35995940/article/details/78433404?locationNum=5&fps ...
随机推荐
- AndroidManifest.xml中的<uses-feature>以及和<uses-permission>之间的联系
概述:<uses-feature>用来声明应用中需要用的硬件和软件的功能. 硬件特性:表明您的应用需要用的硬件功能. 功能类型 特征描述 描述 音频 android.hardware.au ...
- html 网页源码解析:bs4中BeautifulSoup
from bs4 import BeautifulSoup result=requests.request("get","http://www.baidu.com&quo ...
- Spring学习之==>IoC
一.概述 Spring的三大核心思想:IoC(控制反转),DI(依赖注入),AOP(面向切面编程).本问讲着重介绍一下控制反转. 何谓控制反转:Spring 通过一种称作控制反转(IoC)的技术促进了 ...
- linux 基础 文件操作
cat -A /etc/passwdnl -ba passwd cat -A man_db.conf more man_db.conf less man_db.conf head -n 5 /var/ ...
- jQuery事件操作
bind绑定事件 bind(type,data,fn) [参数描述] type (String) : 事件类型 data (Object) : (可选) 作为event.data属性值传递给事件对象的 ...
- 【Linux开发】linux设备驱动归纳总结(四):3.抢占和上下文切换
linux设备驱动归纳总结(四):3.抢占和上下文切换 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...
- Java拆箱装箱
原文 http://www.cnblogs.com/dolphin0520/p/3780005.html
- Python globals()和locals()比较
Python的两个内置函数,globals()和locals() ,它们提供了基于字典的访问局部和全局变量的方式. globals()是可写的,即,可修改该字典中的键值,可新增和删除键值对. 而loc ...
- [python] 在指定目录下找文件
import os # 查找当前目录下所有包含关键字的文件 def findFile(path, filekw): return[os.path.join(path,x) for x in os.li ...
- linux 下各errno的意义(转)
linux 下各errno的意义(转) 本文转自:http://blog.csdn.net/kofiory/article/details/5790409 strerror(errno):获取er ...