Oracle rs.getClob("")转String

oracle数据中定义为clob类型的字段,如果用rs.getString()方法获取,值一直为nul,无法取出

用rs.getClob()取出来为Clob型

需把Clob型转为String类型

 

Java 代码

            rs = pstmt.executeQuery();
while(rs.next()){
Reader reader = rs.getClob("afterStepScript")
.getCharacterStream();
BufferedReader r = new BufferedReader(reader);
StringBuffer sb = new StringBuffer();
String line;
try {
while ((line = r.readLine()) != null) {

sb.append(line);
//sb.append("\r\n");
}
} catch (IOException e) {
e.printStackTrace();
}

String afterStepScript=sb.toString();

 或者

         Clob clob=rs.getClob("insideScript");
String insideScript="";
if(clob!=null){
insideScript=clob.getSubString((long)1, (int)clob.length());
}

后一种方式效率更高一些

你可能感兴趣的:(oracle)