自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

不同數(shù)據(jù)庫對blob字段的處理代碼演示

數(shù)據(jù)庫
本文主要介紹了不同的數(shù)據(jù)庫或程序開發(fā)語言對BLOB字段的處理過程詳細(xì)代碼,通過代碼讓我們來了解它們的處理過程吧,希望能對讀者有所幫助。

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

1)spring配置文件:

 

  1. <bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/> 
  2.  
  3. <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> 
  4.  
  5. <property name="configLocation" value="classpath:conf/sqlMapConfig.xml"></property> 
  6.  
  7. <property name="dataSource" ref="dataSource2"></property> 
  8.  
  9. <property name="lobHandler" ref="lobHandler"></property> 
  10.  
  11. </bean> 

 

2)Ibatis配置文件:

 

  1. sqlMapConfig.xml:  
  2.  
  3. <?xml version="1.0" encoding="UTF-8"?> 
  4.  
  5. <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"  
  6.  
  7. "http://www.ibatis.com/dtd/sql-map-config-2.dtd"> 
  8.  
  9. <sqlMapConfig>   
  10.  
  11. <properties resource="conf/serverity.properties" />   
  12.  
  13. <settings  useStatementNamespaces="true" cacheModelsEnabled="false" maxRequests="256" 
  14.  
  15. maxSessions="64" maxTransactions="16"/> 
  16.  
  17. <typeHandler  jdbcType="BLOB" javaType="[B"callback="org.springframework.orm.ibatis.support.BlobByteArrayTypeHandler"/> 
  18.  
  19. <sqlMap resource="conf/sqlmap/monitorSqlMap.xml" /> 
  20.  
  21. </sqlMapConfig> 
  22.  
  23. monitorSqlMap.xml:  
  24.  
  25. <?xml version="1.0" encoding="UTF-8"?> 
  26.  
  27. <!DOCTYPE sqlMap  
  28.  
  29. PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"  
  30.  
  31. "http://www.ibatis.com/dtd/sql-map-2.dtd"> 
  32.  
  33. <sqlMap namespace="favMonitor"> 
  34.  
  35. <select id="queryVoBytes" parameterClass="java.util.Map" resultClass="[B"> 
  36.  
  37. select voListBytes from t_favMonitor where userId=#userId# and reqName=#reqName#  
  38.  
  39. </select> 
  40.  
  41. </sqlMap> 

 

3) mysql數(shù)據(jù)庫:

 

  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.  

 

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

【編輯推薦】

  1. 共享database獨立Schema構(gòu)建SAAS平臺
  2. ASP通過Oracle Object for OLE對Oracle查詢
  3. Oracle跟蹤文件分析工具TKPROF使用簡介
  4. 如何配置Oracle 10g oem中的主機(jī)身份證明
  5. PLSQL Developer8連接Oracle 10g X64版報錯的解決
責(zé)任編輯:趙鵬 來源: 博客園
相關(guān)推薦

2010-04-23 14:32:01

Oracle數(shù)據(jù)庫

2010-04-29 10:56:46

Oracle數(shù)據(jù)庫

2010-04-20 10:12:42

OraclePL

2017-10-23 16:06:41

數(shù)據(jù)庫MySQL復(fù)制中斷

2011-07-11 14:36:10

BinlogMysql

2010-05-28 14:51:47

MySQL數(shù)據(jù)庫

2010-05-12 18:41:34

MySQL數(shù)據(jù)庫

2010-05-21 15:33:54

MySQL text

2011-07-12 16:41:14

mysql處理異常

2009-08-25 16:01:32

C#.NET連接數(shù)據(jù)庫

2010-04-14 15:58:17

Oracle程序開發(fā)

2019-10-24 08:01:45

MySQL遷移數(shù)據(jù)庫

2025-01-10 09:15:57

2010-04-19 09:26:04

Oracle數(shù)據(jù)庫

2010-06-09 17:36:45

MySQL數(shù)據(jù)庫同步

2017-05-25 10:23:13

數(shù)據(jù)a表b表

2010-06-04 09:33:28

連接MySQL數(shù)據(jù)庫

2010-06-12 17:55:23

MySQL數(shù)據(jù)庫同步

2011-08-18 18:34:00

Oracle數(shù)據(jù)庫創(chuàng)建自增字段

2010-06-04 10:40:55

AJAX MySQL
點贊
收藏

51CTO技術(shù)棧公眾號