时间:2020-12-16 10:27:19 | 栏目:JAVA代码 | 点击:次
Oracle数据库中有一个字段是CLOB类型,使用java 解析.
1.使用java解析clob类型内容
public String clobToString(Clob c) { StringBuffer sb = new StringBuffer(1024); Reader instream = null; try { instream = c.getCharacterStream(); char[] buffer = new char[(int) c.length()]; int length = 0; while ((length = instream.read(buffer)) != -1) { sb.append(buffer, 0, length); } } catch (Exception ex) { ex.printStackTrace(); return null; } finally { try { if (instream != null) instream.close(); } catch (Exception dx) { instream = null; } } return sb.toString(); }
if(pageObject.getResultList() != null && pageObject.getResultList().size() > 0){ for(int i=0,j=pageObject.getResultList().size(); i < j;i++){ Map<String,Object> maps = (Map<String, Object>) pageObject.getResultList().get(i); maps.put("DISPATCHINGRULESNAME",this.clobToString((Clob) maps.get("DISPATCHINGRULESNAME"))); //这里将Clob类型转化成字符串,调用clobToString((Clob)方法 } }
2.使用oracle函数 to_char(字段)
select to_char(t.billName) as billName from T_CC_SHARE_DISPATCH_RULE t