首页 > 编程语言 > 详细

Java 将Clob字段转换成String字符串

时间:2020-08-14 10:21:10      阅读:75      评论:0      收藏:0      [点我收藏+]

一、使用JDBC数据源获取的Clob字段转换String字符串。

public static Object clobToString(Object in) throws Exception {
        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;
            }
        }catch (Exception e) {
            // TODO: handle exception
            return in;
        }
        
    }

二、使用WebLogic数据源获取的Clob字段转换String字符串。

public static Object clobToString1(Object in) throws Exception {

        try {
            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;
            }
        } catch (Exception e) {
            // TODO: handle exception
            return in;
        }
    }

 

Java 将Clob字段转换成String字符串

原文:https://www.cnblogs.com/sinosoft/p/13500590.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!