日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯網營銷解決方案
不同數據庫對blob字段的處理代碼演示

spring、Ibatis、mysql和java處理blob字段的方法是不同的,本文給出了處理過程的詳細代碼,現在一一開始介紹。

1)spring配置文件:

 
 
 
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  

2)Ibatis配置文件:

 
 
 
  1. sqlMapConfig.xml:  
  2.  
  3.  
  4.  
  5.  
  6. "http://www.ibatis.com/dtd/sql-map-config-2.dtd"> 
  7.  
  8.    
  9.  
  10.    
  11.  
  12.  
  13. maxSessions="64" maxTransactions="16"/> 
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. monitorSqlMap.xml:  
  22.  
  23.  
  24.  
  25.  
  26. PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"  
  27.  
  28. "http://www.ibatis.com/dtd/sql-map-2.dtd"> 
  29.  
  30.  
  31.  
  32.  
  33.  
  34. select voListBytes from t_favMonitor where userId=#userId# and reqName=#reqName#  
  35.  
  36.  
  37.  
  38.  

3) mysql數據庫:

 
 
 
  1. table:  t_favMonitor(userid int, reqName varchar, voListBytes blob) 

4) java存?。?/strong>

 
 
 
  1. private static class ByteObjectUtil{  
  2.  
  3. static byte[] convertObj2ByteArray(Object obj) throws IOException{  
  4.  
  5. ByteArrayOutputStream baos=null;  
  6.  
  7. ObjectOutputStream oos=null;  
  8.  
  9. try {  
  10.  
  11. baos=new ByteArrayOutputStream();  
  12.  
  13. oos=new ObjectOutputStream(baos);  
  14.  
  15. oos.writeObject(obj);  
  16.  
  17. return baos.toByteArray();  
  18.  
  19. } catch (IOException e) {  
  20.  
  21. throw new IOException(e);  
  22.  
  23. }finally{  
  24.  
  25. baos.close();  
  26.  
  27. oos.close();  
  28.  
  29. }  
  30.  
  31. }  
  32.  
  33. static Object readObjFromByteArray(byte[] ob) throws IllegalStateException, IOException, ClassNotFoundException{  
  34.  
  35. if(ob==null||ob.length==0)  
  36.  
  37. throw new IllegalStateException("parameter byte[] ob is empty!");  
  38.  
  39. ByteArrayInputStream bais=new ByteArrayInputStream(ob);  
  40.  
  41. ObjectInputStream ois=null;  
  42.  
  43. try {  
  44.  
  45. ois=new ObjectInputStream(bais);  
  46.  
  47. return ois.readObject();  
  48.  
  49. } catch (IOException e) {  
  50.  
  51. throw new IOException(e);  
  52.  
  53. }finally{  
  54.  
  55. bais.close();  
  56.  
  57. ois.close();  
  58.  
  59. }  
  60.  
  61. }  
  62.  

關于處理blob字段的方法就介紹到這里,如果您想了解更多數據庫方面的知識,可以到這里看一看:http://database./,謝謝各位的支持。


新聞名稱:不同數據庫對blob字段的處理代碼演示
網頁路徑:http://www.5511xx.com/article/dhohjjh.html