• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Keeping Images for a Employee Object

 
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers ,

I am making a Emplyoyee Object with all their variables like Age , EmpId , Name ,sal so for this i produced getters and setters of each variable.

I also want to keep a Image/photo of the Employee . what is the way to proceed?

Do i need to produce setters and getters of Blob tpye ? If so what is the datatype i need to put on to the Employee Object for this ?

If this is not the efficient way , can anybody please tell me whats the way to do this ?
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use InputStream.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya i will be doing this at the time of retreival

Blob b = rs.getBlob(2);

InputStream iis = b.getInputStream();

But what about setter and getters on to the Employee Object and the datatype there to be used ??

I think you got my question .
 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of what use would it be? How does one show an image in an HTML page? With a Blob? No, with an <img> tag to a separate resource.

So with that in mind, how would you proceed?
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Employee class Images should be declared as




You can save byte array as blob in database and retrieve the data in back in array.

But to serve image to browser, you cannot use this VO|DTO directly, you have to create a new servlet to server binary image data. Use URL of servlet in <img> tag.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Alok ,

Bear thanks for your concern ,i am trying to proceed in this way :

i will be pointing out to File which is written with the help of the InputStream from the Blob .with the help of the Image tag from the JSP. what do you think is this the way to go ??
 
Bear Bibeault
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't necessarily have to write to a file. Whatever URl the <img> tag references can be a servlet that streams the image data.
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic