今天写程序需要把String转成Clob,找了好几种有关数据库插入的,找同事要了一种方法,如下:
java.sql.Clob c = new javax.sql.rowset.serial.SerialClob("abc".toCharArray())
附带clob转成String 的代码
// clob字段转字符串
public static String ClobToString(Clob clob) {
String reString = "";
try {
if(clob!=null){
Reader is = clob.getCharacterStream();// 得到流
StringBuilderbr = new StringBuilder(is);
String s = br.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {
sb.append(s);
s = br.readLine();
}
reString = sb.toString();
}else{
return reString;
}
} catch (Exception e) {
e.printStackTrace();
throw new RRException("转string异常");
}
return reString;
}