日期:2014-05-16 浏览次数:20494 次
public static List queryListBlob(String sql,JdbcTemplate sjt){
??List list=null;
?list = sjt.query(sql, new RowMapper(){
???public Object mapRow(ResultSet rs, int i) throws SQLException {
?????????? Map results = new HashMap();//存放对像的hashmap
?????????? CLOB clob = null;
?????????? String str = "";
?????????? try {
?????????? ?T_CASESTUDY bean=new T_CASESTUDY();//表对应的javaBean
?????????? ?clob = (oracle.sql.CLOB) rs.getClob("content");//content字段属性为clob,转成clob对象
????????????str = clobToString(clob);将clob对象转为String
????????????bean.setId(rs.getString("id"));
?????????? ?bean.setName(rs.getString("name"));
?????????? ?bean.setWebsite(rs.getString("website"));
?????????? ?bean.setImgpath(rs.getString("imgpath"));
?????????? ?bean.setContent(str);
?????????? ?bean.setCrdt(rs.getDate("crdt"));
?????????? ?bean.setCrusr(rs.getString("crusr"));
?????????? ?bean.setOrderid(rs.getInt("orderid"));
?????????? ?bean.setState(rs.getString("state"));
?????????? ?results.put(rs.getString("id"),bean);
?????} catch (Exception e) {
??????logger.error(e.getMessage());
??????results.put("content", "");
?????}???????????
?????????? return results;
??? }
??? //此方法将clob转为String
??? public String clobToString(CLOB clob) throws SQLException, IOException {
?????String reString = "";
?????if( clob == null || clob.getCharacterOutputStream() == null )
??????return "";
?????Reader is = clob.getCharacterStream();// 得到流
?????BufferedReader br = new BufferedReader(is);
?????String s = br.readLine();
?????StringBuffer sb = new StringBuffer();
?????while (s != null) {// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
??????sb.append(s);
??????s = br.readLine();
?????}
?????reString = sb.toString();
?????return reString;
????}
??});
}