用weblogic连接池里面获取到得连接查询oracle clob字段的数据,类型是weblogic.jdbc.wrapper.Clob_oracle_sql_CLOB,强转成oracle.sql.CLOB会报错,但是weblogic.jdbc.wrapper.Clob_oracle_sql_CLOB里面有个属性恰恰就是oracle.sql.CLOB,通过反射可以找到oracle.sql.CLOB,代码如下:
private Object clobToString(Object in){
try{if ("oracle.sql.CLOB".equals(in.getClass().getName())){
String rtn = "";
oracle.sql.CLOB clob = (oracle.sql.CLOB)in;
InputStream input = clob.getAsciiStream();
int len = (int)clob.length();
byte[] by = new byte[len];
int i ;
while(-1 != (i = input.read(by, 0, by.length))) {
input.read(by, 0, i);
}
rtn = new String(by);
rtn=clob.getSubString((long)1,(int)clob.length());
return rtn;
}else if ("weblogic.jdbc.wrapper.Clob_oracle_sql_CLOB".equals(in.getClass().getName())){
String rtn = "";
Method method = in.getClass().getMethod("getVendorObj",new Class[]{});
oracle.sql.CLOB clob = (oracle.sql.CLOB)method.invoke(in);
InputStream input = clob.getAsciiStream();
int len = (int)clob.length();
byte[] by = new byte[len];
int i ;
while(-1 != (i = input.read(by, 0, by.length))) {
input.read(by, 0, i);
}
rtn = new String(by);
rtn=clob.getSubString((long)1,(int)clob.length());
return rtn;
}else{
return in;
}
}catch (Exception e){
return in;
}
}