1: Increase operation
Public intaddtest (Testvo TV) {byteBz[] =tv.getbz (). GetBytes (); Lobhandler Lobhandler=NewDefaultlobhandler (); String SQL= "INSERT into Test (NAME,AGE,BZ) VALUES (?,?,?)"; returnJdbctpl.execute (SQL,NewAbstractlobcreatingpreparedstatementcallback (lobhandler) {@Overrideprotected voidSetvalues (PreparedStatement PS, Lobcreator lobcreator)throwsSQLException, DataAccessException {ps.setstring (1, Tv.getname ()); Ps.setint (2, Tv.getage ()); Lobcreator.setblobasbytes (PS,3, BZ); } }); }
2: Query operation
PublicList<testvo>gettestlist () {String SQL= "Select Name,age,bz from Test"; returnJdbctpl.query (SQL,Newobject[]{},NewRowmapper<testvo>() {@Override PublicTestvo Maprow (ResultSet RS,intRowNum)throwsSQLException {testvo TV=NewTestvo (); Tv.setname (Rs.getstring ("Name")); Tv.setage (Rs.getint ("Age")); InputStream is= Rs.getblob ("BZ"). Getbinarystream (); Bytearrayoutputstream out=NewBytearrayoutputstream (); intLen = 0; Try { while((Len=is.read ())!=-1) {out.write (len); } tv.setbz (Base64utils.encodetostring (Out.tobytearray ())); } Catch(IOException e) {e.printstacktrace (); } finally { Try { if(NULL!=Out ) {Out.close (); } } Catch(IOException e) {e.printstacktrace (); }finally { Try { if(is!=NULL) {is.close (); } } Catch(IOException e) {e.printstacktrace (); } } } returnTV; } }); }
JdbcTemplate Manipulating Oracle BLOBs