乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Hibernate將文件二進制存入mysql

       LibraryPKU 2014-04-07
      二進制大型對象(BLOB)列是MySQL的秘密武器之一。這些列中存儲了二進制的數(shù)據(jù),你可以象其它普通的數(shù)據(jù)類型一樣來檢索和操縱它。根據(jù)MySQL指南有關(guān)資料,BLOB是一個二進制大型對象,它能容納不同大小的數(shù)據(jù)。事實上,MySQL有四種BLOB類型:

      ◆tinyblob:僅255個字符
      ◆blob:最大限制到65K字節(jié)
      ◆mediumblob:限制到16M字節(jié)
      ◆longblob:可達4GB


      Java代碼
      1. String fname = "c:\\itanger.gif";//要入庫的文件    
      2. File f = new File(fname);    
      3. FileInputStream fin = new FileInputStream(f);    
      4. tad.setImage(Hibernate.createBlob(fin));   
      1. String fname = "c:\\itanger.gif";//要入庫的文件   
      2. File f = new File(fname);   
      3. FileInputStream fin = new FileInputStream(f);   
      4. tad.setImage(Hibernate.createBlob(fin));   


      Java代碼
      1. public void doGet(HttpServletRequest request,HttpServletResponse response){   
      2.         User user=(User)session.load(User.classnew Integer(1));   
      3.         Blob photo=user.getPhoto();   
      4.         InputStream in=photo.getBinaryStream();   
      5.         OutputStream out=response.getOutputStream();   
      6.         byte [] buf=new byte[1024];   
      7.         int len;   
      8.         while((len=in.read(buf))!=-1){   
      9.             out.write(buf, 0, len);   
      10.         }   
      11.         in.close();   
      12.         out.close();   
      13.     }  

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多