-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: save image in mysql using java
PostPosted: Wed Nov 25, 2009 4:07 pm 
Newbie

Joined: Wed Nov 25, 2009 3:58 pm
Posts: 2
somebody can I help me? how save image in mysql using java SE with hibernate. how I can configure the file of mappring of hibernate. I dont have any idea


Top
 Profile  
 
 Post subject: Re: save image in mysql using java
PostPosted: Wed Nov 25, 2009 6:30 pm 
Beginner
Beginner

Joined: Thu Jun 21, 2007 9:24 pm
Posts: 20
Location: Lansing, Michigan, USA
I would suggest using a MySQL type of BLOB or MEDIUMBLOB (depending on whether your images are all smaller than 64k or all smaller than 16M), a Java type of byte[], marking the column as lazy, and interpreting the image data at a higher level (say in your GUI code, using ImageIcon.ImageIcon(byte[]) ).

Your .hbm.xml file would have a section like:
Code:
  <class name="person" table="person" >
     ...
     <property name="photo" type="blob" lazy="true" access="field" />
     ...


Your data-model class would expose the image data, but is could also have a helper method to create a renderable version of the image:
Code:
public class Person {
  ...
  private byte[] photo;
  ...
  public Icon loadPhoto() {
    if (photo != null)
      return new ImageIcon(photo);
    else
      return new ImageIcon(Person.class.getResource("noface.png"));
  }


As far as saving the image ... you don't say where it's coming from: the local filesystem? Uploaded to a web application? Generated in-memory (say with WritableRenderedImage)?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.