Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JBoss User Help »

[jboss-user] [EJB 3.0] - image to blob

scott.stark@jboss.org

2007-08-07


Hello,

I have problem with Blob type.

A Image should be uploaded then stored in tempory file. The image should be stored from tempory file into mysql over enitity bean as Blob Object.

How can I make from image to blob object without SQL-statement?

Enitity Bean InterpreterImage

| public class InterpreterImage implements Serializable
| {
|  private static final long serialVersionUID = 1L;
|
|  @Id
|  @Column(name="ID")
|  private int id;
|  
|  @Column(name="GALLERYFILENAME")
|  private String galleryFilename;
|  
|  @Column(name="GALLERYIMAGE")
|  private Blob galleryImage;
|  
|  @Column(name="PROFILFILENAME")
|  private String profilFilename;
|  
|  @Column(name="PROFILIMAGE")
|  private Blob profilImage;
|

Store Blob Object into entity Bean Interpreter.interpreterImage

| ......
| interpreter.getInterpreterImage().setProfilImage(
|          setImagetoPath(profilFile.getInputStream(), filename));
| .....
|

>From Image to Blob Object. But how???

|  private Blob setImagetoPath(InputStream input, String Filename) {
|
|    FileOutputStream fos;
|    Blob blob = null;
|    String realPath=null;
|    byte[] buff = new byte[8192];
|    int len = 0;
|
|    try {
|      System.out.println(Filename);
|      realPath = ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext()).getRealPath("/images");
|      fos = new FileOutputStream(realPath+"/"+Filename);
|      while (0 < (len = input.read(buff))){
|        fos.write(buff, 0, len);
|      }
|      System.out.println(fos.toString());
|      fos.close();
|      input.close();
|    } catch (FileNotFoundException e) {
|      // TODO Auto-generated catch block
|      e.printStackTrace();
|    } catch (IOException e) {
|      // TODO Auto-generated catch block
|      e.printStackTrace();
|    }
|    try {
|               //Image over byte[] buff to Blob Object
|               // HOW????
|    } catch (SQLException e) {
|      // TODO Auto-generated catch block
|      e.printStackTrace();
|    }
|    return blob;
|  }
|

Store simple Bean into database

|  public void createInterpreter(Interpreter interpreter) {
|    manager.persist(interpreter);
|  }
|
I hope, that you have an idea... Thank you in advance

Manu


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071499#4071499

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071499
_______________________________________________
jboss-user mailing list
jboss-user@(protected)
https://lists.jboss.org/mailman/listinfo/jboss-user
©2008 junlu.com - Jax Systems, LLC, U.S.A.