1) Spring configuration file:
<Bean id = "lobhandler" class = "org. springframework. JDBC. Support. lob. defaultlobhandler"/>
<Bean id = "sqlmapclient" class = "org. springframework. Orm. ibatis. sqlmapclientfactorybean">
<Property name = "configlocation" value = "classpath: CONF/sqlmapconfig. xml"> </property>
<Property name = "datasource" ref = "performance2"> </property>
<Property name = "lobhandler" ref = "lobhandler"> </property>
</Bean>
2) ibatis configuration file:
Sqlmapconfig. xml:
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype sqlmapconfig public "-// ibatis.com//dtd SQL map config 2.0/EN"
Http://www.ibatis.com/dtd/sql-map-config-2.dtd>
<Sqlmapconfig>
<Properties resource = "CONF/serverity. properties"/>
<Settings usestatementnamespaces = "true" cachemodelsenabled = "false" maxrequests = "256" maxsessions = "64" maxtransactions = "16"/>
<Typehandler jdbctype = "blob" javatype = "[B" Callback = "org. springframework. Orm. ibatis. Support. blobbytearraytypehandler"/>
<Sqlmap resource = "CONF/sqlmap/monitorsqlmap. xml"/>
</Sqlmapconfig>
Monitorsqlmap. xml:
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype sqlmap
Public "-// ibatis.com//dtd SQL map 2.0 // en"
Http://www.ibatis.com/dtd/sql-map-2.dtd>
<Sqlmap namespace = "favmonitor">
<Select id = "queryvobytes" parameterclass = "Java. util. Map" resultclass = "[B">
Select volistbytes from t_favmonitor where userid = # userid # And reqname = # reqname #
</SELECT>
</Sqlmap>
3) MySQL database:
Table: t_favmonitor (userid int, reqname varchar, volistbytes BLOB)
4) Java access:
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 ();
}
}
}