BLOB Image Storage With Spring Hibernate and Struts2
BLOB Image Storage With Spring Hibernate and Struts2
CiphorBlog
dev life buzz
What is BLOB?
A blob (alternately known as a binary large object, basic large object, BLOB, or BLOb) is a collection of binary data stored as a single entity in a database management system. Blobs are typically images, audio or other multimedia objects, though sometimes binary executable code is stored as a blob. Database support for blobs is not universal. - From Wikipedia. We often store unstructured data into a LOB field in database, and LOB is normally known as BLOB(Binary) and CLOB(Character). The LOB datatypes BLOB, CLOB, NCLOB, and BFILE enable you to store large blocks of unstructured data (such as text, graphic images, video clips, and sound waveforms) up to 4 gigabytes in size. They provide efficient, random, piece-wise access to the data. Oracle Corporation recommends that you always use LOB datatypes over LONG datatypes.- Oracle Docs.
Steps I followed
DefaultLobHandler
First we need to add spring Blob handler into configuration xml. Declare a bean definition and inject it into sessionFactory. 0 <- Srn DfutLBHnlr-> 1 !- pig eal O ade 0 2 <eni=lbade" ba d"oHnlr cas"r.pigrmwr.dcspotlbDfutoHnlr lz-nt"re / ls=ogsrnfaeokjb.upr.o.ealLbade" ayii=tu" > 0 3 0 4 <- HbraeSsinatr -> !- ient esoFcoy 0 5 <eni=ssinatr" ba d"esoFcoy cas"r.pigrmwr.r.ient3antto.noainesoFcoyen> ls=ogsrnfaeokomhbrae.noainAnttoSsinatrBa" 0 6 <rprynm=dtSuc"rf"aaore/ poet ae"aaore e=dtSuc"> 0 7 <rprynm=cniLcto"vle"lspt:ient.f.m"> poet ae"ofgoain au=casahhbraecgxl/ 0 8 <rprynm=hbraerpris> poet ae"ientPoete" 0 9 <au> vle 1 0 hbraedaet$hbraedaet ient.ilc={ient.ilc} 1 1 hbraeqeysbtttostu '' fle'' ient.ur.usiuin=re Y, as N 1 2 hbraecceuescn_ee_ah=re ient.ah.s_eodlvlccetu 1 3 hbraeso_q=re ient.hwsltu 1 4 hbraeccepoie_ls=r.ient.ah.hahPoie ient.ah.rvdrcasoghbraecceECcervdr 1 5 <vle /au> 1 6 <- Tr bthn offrbte errmsae udrPsgeQ -> !- un acig f o etr ro esgs ne otrSL 1 7 <- hbraejb.ac_ie0-> !- ient.dcbthsz= 1 8 <poet> /rpry 1 9 <rprynm=lbade"rf"oHnlr/ poet ae"oHnlr e=lbade">
www.ciphor.com/blog/blob-image-storage-with-spring-hibernate-and-struts2/ 1/6
08/03/13
2 0
<ba> /en
08/03/13
1 9 2 0 2 1 2 2 2 3
In spring service you need handle the struts input with springs FileCopyUtils class: 0 @rnatoa(edny fle 1 TascinlraOl= as) 0 2 pbi vi svFWrIf(saenofWrIf,Fl[ iae ulc od aesaenoFWrIf saeno ie] mg, 0 3 Srn[ iaeotnTp,Srn[ iaeieae tig] mgCnetye tig] mgFlNm) 0 4 trw IEcpin{ hos Oxeto 0 5 0 6 i (mg.egh! 0| iae! nl){ f iaelnt = | mg = ul 0 7 fr(n i=0 i<iaelnt;i+ { o it ; mg.egh +) 0 8 bt[ flAry=ogsrnfaeokui.ieoytl ye] iera r.pigrmwr.tlFlCpUis 0 9 .oyoyera(mg[]; cpTBtAryiaei) 1 0 FWrIae fWrIae=nwFWrIae(; saemgs saemg e saemgs) 1 1 fWrIaestmgDt(iera) saemg.eIaeaaflAry; 1 2 fWrIaestmgSz(e Ln(iera.egh) saemg.eIaeienw ogflArylnt); 1 3 fWrIaestmgTp(mgCnetyei) saemg.eIaeyeiaeotnTp[]; 1 4 fWrIaestaedfWrIf.eI() saemg.eWrI(saenogtd); 1 5 fWrIf.eFWrIae(.d(saemg) saenogtsaemgs)adfWrIae; 1 6 } 1 7 } 1 8 1 9 fWrIf.eIaeu(e Ln(saenogtsaemgs)sz(); saenostmgNmnw ogfWrIf.eFWrIae(.ie)) 2 0 2 1 sprsv(saeno; ue.aefWrIf) 2 2 }
Finally in JSP
Here goes what the code is like in jsp. 1 <nu tp=fl"i=iae vle" nm=iae> ipt ye"ie d"mg" au=" ae"mg" 2 <m sc"sulato=gtyaiIae> ig r=<:r cin"eDnmcmg" 3 <:aa nm=iaeD vle"d>/:aa> sprm ae"mgI" au=i"<sprm 4 <sul" /:r>>
Demo Snapshot
Here shows a demo snapshot from my previous project with ExtJS organizing the images from database Blobs.
Related posts: 1. How to Build a Dynamic Tree with Dojo,DWR,Spring and Hibernate 2. How to integrate Spring HttpInvoker with Java Applet
www.ciphor.com/blog/blob-image-storage-with-spring-hibernate-and-struts2/ 3/6
08/03/13
3. How to Build Dynamic Tree with ExtJS 4. Howto Enable Lazy Fetch using Hibernate with Spring | 5. Composite Primary Key Mapping with JPA Annotation :applicationContext, blob, hibernate, image, java, spring, struts, struts2, web
medical assistant
June 25th, 2010 on 9:51 pm
found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later [Reply] Reply
WP Themes
July 4th, 2010 on 5:45 pm
Genial fill someone in on and this fill someone in on helped me alot in my college assignement. Thanks you on your information. [Reply] Reply
Louis
September 14th, 2010 on 2:08 pm
Your site is amazing.I am very impressed to see this,i want to come back for visiting your site.Keep doing Good as well as you can.. [Reply] Reply
BLOB Image Storage with Spring Hibernate and Struts2 http://goo.gl/fb/Asxe1 Johannes Geppert
June 13th, 2010 on 5:25 pm
RT @kangleay: BLOB Image Storage with Spring Hibernate and Struts2 http://goo.gl/fb/Asxe1 Tweets that mention BLOB Image Storage with Spring Hibernate and Struts2 -- Topsy.com
June 14th, 2010 on 1:37 am
[...] This post was mentioned on Twitter by Johannes Geppert, kangleay. kangleay said: BLOB Image Storage with Spring Hibernate and Struts2 http://goo.gl/fb/Asxe1 [...]
Leave a Reply
www.ciphor.com/blog/blob-image-storage-with-spring-hibernate-and-struts2/ 4/6
08/03/13
Leave comment
Subscribe in a reader
Tag Cloud
buzz code database dbconsole dev dwr eclipse error extjs firefox firefox plugins good man google hardy heron hibernate html install internet ipod touch java javascript junit life tips linux mac mocking network office oracle pdf personal plugins remote spring struts2 technology test tree treepanel ubuntu unit test unix video web
Agile
Recent Posts
ExtJS Tree Recursive Checking Tweak Java Home in Mac for Oracle Habits Subclipse with Eclipse Helios on Snow Leopard Resolve Error Installing MySql Gem in Snow Leopard BLOB Image Storage with Spring Hibernate and Struts2
Recent Comments
kangleay on ExtJS Tree Recursive Checking treelovers Treehuggers on How to Build Dynamic Tree with ExtJS kangleay on Subclipse with Eclipse Helios on Snow Leopard gabri on Subclipse with Eclipse Helios on Snow Leopard Louis on BLOB Image Storage with Spring Hibernate and Struts2
Categories
buzz
www.ciphor.com/blog/blob-image-storage-with-spring-hibernate-and-struts2/ 5/6
08/03/13
dev life
Meta
Log in Valid XHTML
Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!
Blogroll
A few highly recommended websites...
Archives
All entries, chronologically... December 2010 August 2010 July 2010 June 2010 April 2010 March 2009 February 2009 January 2009 November 2008 October 2008 September 2008 August 2008 Powered by WordPress. Theme: Pixel. Sweet icons by famfamfam. Back to top
www.ciphor.com/blog/blob-image-storage-with-spring-hibernate-and-struts2/
6/6