Clob 转String 类型使用 以及转码问题
来源:互联网 发布:西安软件开发 大专 编辑:程序博客网 时间:2024/05/22 12:02
public class ColbUtil {
/**
* Clob 类型转换成String类型
*
* @param clob
* @return String 转换后的字符串
* @throws Exception
*/
public static String clobString(Clob clob) throws Exception {
if(clob == null) {
return "";
}
BufferedReader br = null;
String str1 = "";
String str2 = null;
Reader is;
try {
is = clob.getCharacterStream();
br = new BufferedReader(is);
while ((str2 = br.readLine()) != null) {
str1 = str1 + str2;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (br != null) {
br.close();
}
}
return str1;
}
public static String toUtf8String(String s) throws UnsupportedEncodingException {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 0 && c <= 255) {
sb.append(c);
} else {
byte[] b;
try {
b = Character.toString(c).getBytes("utf-8");
} catch (Exception ex) {
b = new byte[0];
}
for (int j = 0; j < b.length; j++) {
int k = b[j];
if (k < 0)
k += 256;
sb.append("%" + Integer.toHexString(k).toUpperCase());
}
}
}
return sb.toString();
}
}
/**
* Clob 类型转换成String类型
*
* @param clob
* @return String 转换后的字符串
* @throws Exception
*/
public static String clobString(Clob clob) throws Exception {
if(clob == null) {
return "";
}
BufferedReader br = null;
String str1 = "";
String str2 = null;
Reader is;
try {
is = clob.getCharacterStream();
br = new BufferedReader(is);
while ((str2 = br.readLine()) != null) {
str1 = str1 + str2;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (br != null) {
br.close();
}
}
return str1;
}
public static String toUtf8String(String s) throws UnsupportedEncodingException {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 0 && c <= 255) {
sb.append(c);
} else {
byte[] b;
try {
b = Character.toString(c).getBytes("utf-8");
} catch (Exception ex) {
b = new byte[0];
}
for (int j = 0; j < b.length; j++) {
int k = b[j];
if (k < 0)
k += 256;
sb.append("%" + Integer.toHexString(k).toUpperCase());
}
}
}
return sb.toString();
}
}
0 0
- Clob 转String 类型使用 以及转码问题
- clob类型转String类型
- 数据库Clob类型转String类型
- 数据库Clob类型转String类型
- String类型如何转CLOB 类型
- Java Clob类型转String类型
- java.sql.Clob类型转java.lang.String类型
- clob 转String 、string 转clob
- clob转化String类型
- String转Oracle中的CLOB
- java.sql.Clob转String
- [Java语言] Clob转String
- String转Oracle中的CLOB
- String转java.sql.Clob
- Blob,Clob类型转换String
- Clob转换成String类型
- Clob类型转换成String类型
- Clob类型转换成String类型
- hdu 1242 Rescue(A*索搜)
- MySQL命令行SQL脚本的导入导出小结(数据库的备份与还原)
- Relative与Absolute组合使用
- 关于gridview的item内文字过长换行后显示不完全问题
- 常见C++内存池技术
- Clob 转String 类型使用 以及转码问题
- iphone分辨率终极指南(含iphone6/6+)
- system阻塞SIGCHLD信号原因
- Socket使用教程——AsyncSocket
- iOS9下有关CoreLocation学习三
- Codeforces 416E. President's Path 图论 最短路 处理技巧
- 《数据结构与算法分析(c 描述)》—— 第六章笔记
- NS2在eclipse下的部署以及调试
- xcode 调试