MSG_MSS=javax.sql.rowset.serial.SerialClob@288e89f9Clob:類型的數據查詢出來是一個對象
import java.io.Reader;
import java.sql.Clob;
List<Map<String, Object>> projects = metaService.queryList(sql, null, start, page.getPageSize());
for(Map<String,Object> map:result){
Clob clob = (Clob) map.get("MSG_MSS");
String res = clobToString(clob);
map.put("MSG_MSS", res);
}
//將Clob轉成String類型
public static String clobToString(Clob clob) {
if(clob == null) {
return "";
}
StringBuffer strClob = new StringBuffer();
String str = "";
Reader reader = 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;
}
// 將字Clob轉成String類型
public String ClobToString(Clob sc) throws SQLException, IOException {
String reString = "";
Reader is = sc.getCharacterStream();// 得到流
BufferedReader br = new BufferedReader(is);
String s = br.readLine();
StringBuffer sb = new StringBuffer();
while (s != null) {// 執行循環將字符串全部取出付值給StringBuffer由StringBuffer轉成STRING
sb.append(s);
s = br.readLine();
}
reString = sb.toString();
return reString;
}