一、用流的方法將clob轉爲String類型 (要記的將流關閉)
@Override
public Map<String, Object> queryreviewbaseerrorList(Map<String, Object> map) {
Map<String, Object> mapData = new HashMap<>();
List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
int reviewcode=Integer.parseInt(map.get("reviewcode").toString());
list = DataReviewMapper.queryreviewbaseerrorList(map);
for (Map<String, Object> obj : list) {
Clob sc = (Clob) obj.get("TOPOGEOMETRY");
if(sc!=null){
String TOPOGEOMETRY = null;
try {
TOPOGEOMETRY = ClobToString(sc);
} catch (SQLException | IOException e) {
// TODO 自動生成的 catch 塊
e.printStackTrace();
}
obj.remove("TOPOGEOMETRY");
obj.put("TOPOGEOMETRY", TOPOGEOMETRY);
}
}
PageInfo pInfo = new PageInfo(list);
mapData.put("code", 0);
mapData.put("msg", "");
mapData.put("data", list);
mapData.put("count", pInfo.getTotal());
return mapData;
}
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;
}
二、使用ClobProxyImpl類來解決(比較好)
Map<String,Object> map = clubGroMapper.queryClueGroupDetail(map);
ClobProxyImpl disOrgNoProxy = (ClobProxyImpl)map.remove("distributeOrgNo");//此字段在oracle中爲clob類型
String distributeOrgNo = null;
if(disOrgNoProxy != null){
Clob rawClob = disOrgNoProxy .getRawClob();
distributeOrgNo = rawClob.getSubString(1,(int)rawClob.length());
}
map.put("distributeOrgNo",distributeOrgNo);