hrb_jie 2010-05-12 12:57
浏览 255
已采纳

怎么读取orcl数据库,表中字段是clob类型的一条数据?

A表card字段是clob类型的,里面存储的是和properties文件内容中一样的存储方式,
例如:select.producttype.CPC10313.text=中银王府井百货卡
select.producttype.CPC10313.code=CPC10313
select.producttype.CPC10313.isphoto=0

select.producttype.CPC10318.text=欧尚阿卡中银联名卡
select.producttype.CPC10318.code=CPC10318
select.producttype.CPC10318.isphoto=0

我只想要其中的一条数据,但我读取出所有数据是乱码,代码如下:
String strSql = "select properties from boc_bccs_sysparam b where b.id=3";
ResultSet rs = stmt.executeQuery(strSql);
if (rs.next()) {
CLOB clob = ((OracleResultSet) rs).getCLOB(1);
if (clob != null) {
Reader reader = clob.characterStreamValue();

                String string = IOUtils.toString(reader);
                string=new String(string.getBytes("ISO-8859-1"),"GBK");
                InputStream inputStream = IOUtils.toInputStream(string);
                Properties props = new Properties();

                props.load(inputStream);
                Set<Entry<Object, Object>> entrySet = props.entrySet();
                ProductType productType=null;
                for(Entry<Object,Object> entry:entrySet){
                    String key=(String) entry.getKey();
                    String value=(String) entry.getValue();
                    if(key.startsWith                ("select.producttype"&&key.endsWith("text")){
                        String[] keyArr=key.split("\\.");
                        productType=new ProductType();
                        productType.setCode(keyArr[2]);
                        productType.setText(value);
                        productTypeList.add(productType);
                    }
                }

运行结果如下:
CPC10205===??????????????6????????????¨??ê????±í
CPC20207===????????JCB°????????¨
CPC10001===??????????????????¨??ê????±í
CPC20234===????????·????????????????????????????¨
CJY03===??????????????????????????¨

  • 写回答

7条回答 默认 最新

  • 拽拽的初行者 2010-05-12 13:54
    关注

    [b]那就在getvalue的时候,转码转回来。
    [/b]
    [code="java"]
    String value=(String) entry.getValue();

    // 试试
    value = new String(value.getByte("ISO8859-1"),"GBK");
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?