新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
不同數(shù)據(jù)庫(kù)對(duì)blob字段的處理代碼演示
spring、Ibatis、mysql和java處理blob字段的方法是不同的,本文給出了處理過(guò)程的詳細(xì)代碼,現(xiàn)在一一開始介紹。

1)spring配置文件:
2)Ibatis配置文件:
- sqlMapConfig.xml:
- "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
- maxSessions="64" maxTransactions="16"/>
- monitorSqlMap.xml:
- PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
- "http://www.ibatis.com/dtd/sql-map-2.dtd">
- select voListBytes from t_favMonitor where userId=#userId# and reqName=#reqName#
3) mysql數(shù)據(jù)庫(kù):
- table: t_favMonitor(userid int, reqName varchar, voListBytes blob)
4) java存?。?/strong>
- private static class ByteObjectUtil{
- static byte[] convertObj2ByteArray(Object obj) throws IOException{
- ByteArrayOutputStream baos=null;
- ObjectOutputStream oos=null;
- try {
- baos=new ByteArrayOutputStream();
- oos=new ObjectOutputStream(baos);
- oos.writeObject(obj);
- return baos.toByteArray();
- } catch (IOException e) {
- throw new IOException(e);
- }finally{
- baos.close();
- oos.close();
- }
- }
- static Object readObjFromByteArray(byte[] ob) throws IllegalStateException, IOException, ClassNotFoundException{
- if(ob==null||ob.length==0)
- throw new IllegalStateException("parameter byte[] ob is empty!");
- ByteArrayInputStream bais=new ByteArrayInputStream(ob);
- ObjectInputStream ois=null;
- try {
- ois=new ObjectInputStream(bais);
- return ois.readObject();
- } catch (IOException e) {
- throw new IOException(e);
- }finally{
- bais.close();
- ois.close();
- }
- }
- }
關(guān)于處理blob字段的方法就介紹到這里,如果您想了解更多數(shù)據(jù)庫(kù)方面的知識(shí),可以到這里看一看:http://database./,謝謝各位的支持。
分享名稱:不同數(shù)據(jù)庫(kù)對(duì)blob字段的處理代碼演示
標(biāo)題路徑:http://m.fisionsoft.com.cn/article/dhohjjh.html


咨詢
建站咨詢
