久久精品国产亚洲怮怮_奇米网777色在线精品_亚洲色中文字幕制服丝袜_久久精品人人做人人看

始創(chuàng)于2000年 股票代碼:831685
咨詢(xún)熱線:0371-60135900 注冊(cè)有禮 登錄
  • 掛牌上市企業(yè)
  • 60秒人工響應(yīng)
  • 99.99%連通率
  • 7*24h人工
  • 故障100倍補(bǔ)償
全部產(chǎn)品
您的位置: 網(wǎng)站首頁(yè) > 幫助中心>文章內(nèi)容

Oracle讀取Blob數(shù)據(jù)-通過(guò)JDBC

發(fā)布時(shí)間:  2012/8/26 16:09:48

通過(guò)JDBC讀取Blob數(shù)據(jù),演示代碼

1.  
2.import java.io.File;  3.import java.io.FileOutputStream;  4.import java.io.IOException;  5.import java.io.InputStream;  6.import java.io.OutputStream;  7.import java.sql.Connection;  8.import java.sql.DriverManager;  9.import java.sql.ResultSet;  10.import java.sql.Statement;  11. 
12.public class JDBC {  13.//  public static void main(String[] args) throws Exception {   14.//      // 寫(xiě)入BLOB數(shù)據(jù)   15.//     16.//      // 得到數(shù)據(jù)庫(kù)連接   17.//      Class.forName("Oracle.jdbc.driver.OracleDriver");   18.//   19.//      Connection con = DriverManager.getConnection(   20.//   21.//      "jdbc:Oracle:thin:@192.168.0.68:1521:myOracle", "my", "123");   22.//   23.//      // 處理事務(wù)   24.//   25.//      con.setAutoCommit(false);   26.//   27.//      Statement st = con.createStatement();   28.//   29.//      // 用for update方式鎖定數(shù)據(jù)行   30.//   31.//      ResultSet rs = st.executeQuery(   32.//   33.//      "select content from user_content where id = 2 for update");   34.//   35.//      if (rs.next()) {   36.//   37.//          // 得到j(luò)ava.sql.Blob對(duì)象,然后Cast為Oracle.sql.BLOB   38.//   39.//          Oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);   40.//   41.//          // 到數(shù)據(jù)庫(kù)的輸出流   42.//   43.//          OutputStream outStream = blob.getBinaryOutputStream();   44.//   45.//          // 這里用一個(gè)文件模擬輸入流   46.//   47.//          File file = new File("d:\\proxy.txt");   48.//   49.//          InputStream fin = new FileInputStream(file);   50.//   51.//          // 將輸入流寫(xiě)到輸出流   52.//   53.//          byte[] b = new byte[blob.getBufferSize()];   54.//   55.//          int len = 0;   56.//   57.//          while ((len = fin.read(b)) != -1) {   58.//   59.//              outStream.write(b, 0, len);   60.//   61.//              // blob.putBytes(1,b);   62.//   63.//          }   64.//   65.//          // 依次關(guān)閉(注意順序)   66.//   67.//          fin.close();   68.//   69.//          outStream.flush();   70.//   71.//          outStream.close();   72.//   73.//          con.commit();   74.//   75.//          con.close();   76.//      }   77.//  }   78. 
79.    public static void main(String[] args) throws Exception {  80.        // 讀取BLOB數(shù)據(jù)   81.         
82.        Class.forName("Oracle.jdbc.driver.OracleDriver");  83. 
84.        Connection con = DriverManager.getConnection( 
85. 
86.        "jdbc:Oracle:thin:@192.168.0.68:1521:myOracle", "my", "123");  87. 
88.        con.setAutoCommit(false);  89. 
90.        Statement st = con.createStatement(); 
91. 
92.        // 這里的SQL語(yǔ)句不再需要”for update”   93. 
94.        ResultSet rs = st.executeQuery( 
95. 
96.        "select content from user_content where id = 2");  97. 
98.        if (rs.next()) {  99. 
100.            java.sql.Blob blob = rs.getBlob(1);  101. 
102.            InputStream ins = blob.getBinaryStream(); 
103. 
104.            // 用文件模擬輸出流   105. 
106.            File file = new File("d:\\output.txt");  107. 
108.            OutputStream fout = new FileOutputStream(file);  109. 
110.            // 下面將BLOB數(shù)據(jù)寫(xiě)入文件   111. 
112.            byte[] b = new byte[1024];  113. 
114.            int len = 0;  115. 
116.            while ((len = ins.read(b)) != -1) {  117. 
118.                fout.write(b, 0, len);  119. 
120.            } 
121. 
122.            // 依次關(guān)閉   123. 
124.            fout.close(); 
125. 
126.            ins.close(); 
127. 
128.            con.commit(); 
129. 
130.            con.close(); 
131.        } 
132.    } 
133.} 


 


本文出自:億恩科技【prubsntakaful.com】

服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]

  • 您可能在找
  • 億恩北京公司:
  • 經(jīng)營(yíng)性ICP/ISP證:京B2-20150015
  • 億恩鄭州公司:
  • 經(jīng)營(yíng)性ICP/ISP/IDC證:豫B1.B2-20060070
  • 億恩南昌公司:
  • 經(jīng)營(yíng)性ICP/ISP證:贛B2-20080012
  • 服務(wù)器/云主機(jī) 24小時(shí)售后服務(wù)電話:0371-60135900
  • 虛擬主機(jī)/智能建站 24小時(shí)售后服務(wù)電話:0371-60135900
  • 專(zhuān)注服務(wù)器托管17年
    掃掃關(guān)注-微信公眾號(hào)
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權(quán)所有  地址:鄭州市高新區(qū)翠竹街1號(hào)總部企業(yè)基地億恩大廈  法律顧問(wèn):河南亞太人律師事務(wù)所郝建鋒、杜慧月律師   京公網(wǎng)安備41019702002023號(hào)
      0
     
     
     
     

    0371-60135900
    7*24小時(shí)客服服務(wù)熱線