将数据库中Clob类型转换成java的String类型

来源:互联网 发布:2015年度网络热词 编辑:程序博客网 时间:2024/04/19 02:06
 /**
 * 将数据库中Clob类型转换成java的String类型
 * @param clob
 * @return
 * @throws SQLException
 */
public static String clobtoString(Clob clob) throws SQLException {
        StringBuffer str = new StringBuffer();
        if (clob == null) {
                return null;
        }


        Reader reader = null;
        try {
                reader = clob.getCharacterStream();
                char ac[] = new char[200];
                int i;


                while ((i = reader.read(ac, 0, 200)) != -1) {
                        str.append(new String(ac, 0, i));
                }
        } catch (Exception exception1) {
                throw new SQLException(exception1.getMessage());
        } finally {
                try {
                        reader.close();
                } catch (Exception _ex) {
                }
        }
        return str.toString();

}


private void mian() {

        //map为数据库信息

        String content_xml  = StringUtil.clobtoString((Clob)map.get("content_xml"));
}

原创粉丝点击