读取大数据文件 以oracle为例

本文主要是从数据库读取大数据文件,以eep封装包为例,将XXX.eep封闭包从数据库中读取出来。:

 

public void getClobMedia(String id, String tablename) throws Exception {
		Map map = new HashMap();
		Reader  media = null;
		Statement stmt = this.db.getConnection().createStatement();
		ResultSet rset = null;
		String sql = String.format("SELECT metadata  FROM " + tablename + " where erid='%s'", new Object[] { id });
		this.log.info(sql);
		rset = stmt.executeQuery(sql);
		Clob clob = null;
         while (rset.next()) {
            clob = ((OracleResultSet) rset).getClob(1);
            //version=rset.getString("version");取得字符串
               } 
        if(clob != null){
	    	media = clob.getCharacterStream();
	      	map.put("length", Long.valueOf(clob.length()));

                map.put("media", media);

  }stmt.close();//关闭数据库连接clob = null; //以文件流的方式形如读取数据

               Reader reader =(Reader)map.get("media");
               BufferedReader br=new BufferedReader(reader);
                new File("/eep封装媒体/").mkdirs();
         BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(  "eep封装媒体/eep.eep"),"utf-8"));
               String line = null;
              while((line=br.readLine())!=null)
                   {
                      out.write(line);
                      out.newLine();
                 }
                     out.close();
                      br.close();

 }

 
  

你可能感兴趣的:(java,基础)