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===??????????????????????????¨