<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    甜咖啡

    我的IT空間

    向oracle數(shù)據(jù)庫存儲文件,并讀出文件

    /**
      * 從數(shù)據(jù)庫中查詢IRI和KLO模型的數(shù)據(jù),并下載到本地
      * @param dataTime         時次
      * @param outIRIFilePath   IRI文件下載到本地的路徑
      * @param outKLOFilePath   KLO文件下載到本地的路徑
      * @param outAnaFilePath   插值文件下載到本地的路徑
      */
      @SuppressWarnings("static-access")
      public static void selectBlogInfo(String dataTime, String outIRIFilePath, String outKLOFilePath, String outAnaFilePath) {
      try {
      Connection con = DBConnectionManager.getInstance().getConnection();
      Statement st = con.createStatement();
      String sql = "select * from MODELTEC where DATATIME=to_date('"+dataTime+"', 'YYYY-mm-dd HH24')";
      ResultSet rs = st.executeQuery(sql);
      if (rs.next()) {
      Blob blod = rs.getBlob("IRIDATA");
      InputStream reader = blod.getBinaryStream();
      dataTime = dataTime.replaceAll("-", "");
      dataTime = dataTime.replaceAll(" ", "");
      String iriFilePath = outIRIFilePath+"\\"+dataTime+"0000.iri.grd";
      File file = new File(iriFilePath);
      OutputStream writer;
      writer = new BufferedOutputStream(new FileOutputStream(file));
      byte buf[] = new byte[1024];
      for (int i = 0; (i = reader.read(buf)) > 0;) {
      writer.write(buf, 0, i);
      }
      writer.close();
      reader.close();
     
      blod = rs.getBlob("IRIDATA");
      reader = blod.getBinaryStream();
      String kloFilePath = outKLOFilePath+"\\"+dataTime+"0000.klo.grd";
      file = new File(kloFilePath);
      writer = new BufferedOutputStream(new FileOutputStream(file));
      buf = new byte[1024];
      for (int i = 0; (i = reader.read(buf)) > 0;) {
      writer.write(buf, 0, i);
      }
      writer.close();
      reader.close();
     
      blod = rs.getBlob("ANADATA");
      reader = blod.getBinaryStream();
      String anaFilePath = outAnaFilePath+"\\"+dataTime+"0000.grd";
      file = new File(anaFilePath);
      writer = new BufferedOutputStream(new FileOutputStream(file));
      buf = new byte[1024];
      for (int i = 0; (i = reader.read(buf)) > 0;) {
      writer.write(buf, 0, i);
      }
      writer.close();
      reader.close();
      }
      DBConnectionManager.closeConnection();
      if(con!=null){con.close();}
      if(st!=null){st.close();}
      if(rs!=null){rs.close();}
      } catch (SQLException e) {
      e.printStackTrace();
      } catch (FileNotFoundException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      }
      }
     
      /**
      * 把IRI和KLO模型的文件上傳到數(shù)據(jù)庫中
      * @param dataTime     時次
      * @param iriFilePath  要上傳IRI文件的絕對路徑
      * @param kloFilePath  要上傳KLO文件的據(jù)對路徑
      * @param ANAFilePath  要上傳插值文件的據(jù)對路徑
      */
      @SuppressWarnings("static-access")
      public static void insertBlogInfo(String dataTime, String IRIFilePath, String KLOFilePath, String ANAFilePath) {
      try {
      Connection con = DBConnectionManager.getInstance().getConnection();
      // 處理事務(wù)
      boolean defaultCommit;
      defaultCommit = con.getAutoCommit();
     
      con.setAutoCommit(false);
      Statement st = con.createStatement();
     
      String sql = "select * from MODELTEC where DATATIME=to_date('"+dataTime+"', 'YYYY-mm-dd HH24')";
      ResultSet rs = st.executeQuery(sql);
      if(rs.next()){
      System.out.println(dataTime+"時次已經(jīng)入庫!");
      return ;
      }
      // 插入一個空對象
      sql = "insert into MODELTEC(ID, DATATIME, IRIDATA, KLODATA, ANADATA) values(" +
      "SEQU_MODEL_ID.nextval, " +
      "to_date('"+dataTime+"','YYYY-mm-dd HH24'), " +
      "empty_blob(), " +
      "empty_blob(), " +
      "empty_blob())";
      st.executeUpdate(sql);
      // 用for update方式鎖定數(shù)據(jù)行
      sql = "select IRIDATA,KLODATA,ANADATA from  MODELTEC where DATATIME=to_date('"+dataTime+"', 'YYYY-mm-dd HH24') for update";
      rs = st.executeQuery(sql);
      if (rs.next()) {
      // 得到j(luò)ava.sql.Blob對象,然后Cast為oracle.sql.BLOB
      BLOB blob = (BLOB) rs.getBlob("IRIDATA");
      // 到數(shù)據(jù)庫的輸出流
      OutputStream outStream = blob.getBinaryOutputStream();
      // 這里用一個文件模擬輸入流
      InputStream fin = new FileInputStream(new File(IRIFilePath));
      // 將輸入流寫到輸出流
      byte[] b = new byte[blob.getBufferSize()];
      int len = 0;
      while ((len = fin.read(b)) != -1) {
      outStream.write(b, 0, len);
      }
      // 依次關(guān)閉(注意順序)
      fin.close();
      outStream.flush();
      outStream.close();
     
      // 得到j(luò)ava.sql.Blob對象,然后Cast為oracle.sql.BLOB
      blob = (BLOB) rs.getBlob("KLODATA");
      // 到數(shù)據(jù)庫的輸出流
      outStream = blob.getBinaryOutputStream();
      // 這里用一個文件模擬輸入流
      fin = new FileInputStream(new File(IRIFilePath));
      // 將輸入流寫到輸出流
      b = new byte[blob.getBufferSize()];
      len = 0;
      while ((len = fin.read(b)) != -1) {
      outStream.write(b, 0, len);
      }
      // 依次關(guān)閉(注意順序)
      fin.close();
      outStream.flush();
      outStream.close();
     
      // 得到j(luò)ava.sql.Blob對象,然后Cast為oracle.sql.BLOB
      blob = (BLOB) rs.getBlob("ANADATA");
      // 到數(shù)據(jù)庫的輸出流
      outStream = blob.getBinaryOutputStream();
      // 這里用一個文件模擬輸入流
      fin = new FileInputStream(new File(ANAFilePath));
      // 將輸入流寫到輸出流
      b = new byte[blob.getBufferSize()];
      len = 0;
      while ((len = fin.read(b)) != -1) {
      outStream.write(b, 0, len);
      }
      // 依次關(guān)閉(注意順序)
      fin.close();
      outStream.flush();
      outStream.close();
     
      con.commit();
      /* 恢復(fù)原提交狀態(tài) */
      con.setAutoCommit(defaultCommit);
      DBConnectionManager.closeConnection();
      if(con!=null){con.close();}
      if(st!=null){st.close();}
      if(rs!=null){rs.close();}
      }
      } catch (SQLException e) {
      e.printStackTrace();
      } catch (FileNotFoundException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

    posted on 2012-10-19 13:17 甜咖啡 閱讀(1341) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

    <2012年10月>
    30123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    統(tǒng)計

    常用鏈接

    留言簿(1)

    我參與的團(tuán)隊

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲国产av美女网站| 亚洲电影唐人社一区二区| 日本系列1页亚洲系列| 亚洲人成人网毛片在线播放| 毛片免费全部播放无码| 亚洲熟妇av一区| 曰曰鲁夜夜免费播放视频 | 日本免费中文视频| 免费鲁丝片一级在线观看| 亚洲日韩乱码中文无码蜜桃臀网站 | 亚洲色欲色欲www在线播放 | 亚洲一区二区三区在线| 中文字幕人成无码免费视频| 国产亚洲av人片在线观看| 搡女人免费免费视频观看| 久久国产亚洲电影天堂| 91麻豆最新在线人成免费观看| 亚洲不卡无码av中文字幕| xvideos永久免费入口| 久久精品国产亚洲综合色| 6080午夜一级毛片免费看| 亚洲精品福利你懂| 全部免费a级毛片| 女人隐私秘视频黄www免费| 久久久久亚洲AV片无码下载蜜桃| 久久久久久久国产免费看| 亚洲国产精品自在在线观看| 免费做爰猛烈吃奶摸视频在线观看 | 久久青草免费91观看| 亚洲校园春色另类激情| 又大又硬又爽免费视频| 久热免费在线视频| 亚洲女女女同性video| 亚洲线精品一区二区三区| 一二三四在线播放免费观看中文版视频 | 亚洲国产精品国产自在在线| 国产免费一区二区视频| 亚洲av片不卡无码久久| 亚洲一区日韩高清中文字幕亚洲 | 国产精品无码免费播放| 无遮挡国产高潮视频免费观看|