在oracle里 如果文本超过了4000 达到上W 时...
起几天根据客户的需求。一个小小的表格里面按道理来说总共只有6列、可是每列所需要输入的都是较大的文本、
大家都知道 在进行insert语句的时候 字符类型都只能接受最多4000个字符 在更大的时候就会选用clob
而现在的问题是难道这么一个小小的表格要用到6个clob字段?
占内存太多是个问题、也有可能会让整个程序变得缓慢、、
不知道大家有没有遇上过这个问题、
在这里贴出我解决的方案(本人属于比较菜的程序员、请大家多多包涵哦~)
在数据库里面只用一个clob来存储、而后台则用到MAP键值对的特性来存储不同的字段列文字
在存储的时候把界面上面取得的map对象的值转换位xml类型存储、
取出的时候也是一样~~
提供一下公共的方法:
public static String mapToString(Map map) throws BaseException {
try {
XStream xstream = new XStream();
xstream.alias("content", HashMap.class);
return xstream.toXML(map);
} catch (Exception e) {
throw new BaseException(e);
}
}
/**
* xstream字符串转换成map
* @param xml xstream字符串
* @return map对象
* @throws BaseException 异常
*/
public static Map stringToMap(String xml) throws BaseException {
try {
XStream xstream = new XStream();
xstream.alias("content", HashMap.class);
return (HashMap) xstream.fromXML(xml);
} catch (Exception e) {
throw new BaseException(e);
}
}
这里面需要用到一个xstrem的jar包、哪位大侠能教教我怎么上次附件呢~ (大家就 自己去下载一个吧、)
posted on 2012-02-24 17:40 candiceChan 阅读(459) 评论(0) 收藏 举报
浙公网安备 33010602011771号