Results 1 to 8 of 8
  1. #1
    LovJava is offline Member
    Join Date
    Jan 2010
    Posts
    24
    Rep Power
    0

    Default Storing Images into java through beans

    Hi EveryBody,

    I am working with one of the screen in which image should be stored into the database using the beans setter getter. I've used blob as datatype in the my mysql database.Now i have doubt that to store image which datatype i should use in Java.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    You normally use the setBinaryStream() method of PreparedStatement for saving blobs.
    At least I do.
    Last edited by Tolls; 02-10-2010 at 02:45 PM. Reason: Mucked up link

  3. #3
    LovJava is offline Member
    Join Date
    Jan 2010
    Posts
    24
    Rep Power
    0

    Default

    Sorry i forgot to mention that i am using hibernate too , In my struts form beans which datatype i must use .

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    That's a fairly important bit of info.
    Hibernate has a createBlob() method somewhere or other...ah here you are.
    Give it the input stream from your image and you'll get a blob you can stick in your bean.
    Hibernate can then persist that.

    Getting them out again can be a hassle, from what I remember.

  5. #5
    LovJava is offline Member
    Join Date
    Jan 2010
    Posts
    24
    Rep Power
    0

    Default

    hi Toll,
    Thank you very much for your kind info.

    As per ur instruction i am able insert the image into database. This i have done by converting file into byte array later i called hibernate createBlob method in my dto. Now i have to retriew that image and display it in the screen. So how can you help me.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Creating a byte[] isn't terribly scaleable.
    Surely you have the input stream you could use?

    Anyway, for output...well, suffice to say I've never used hibernate for retrieving blobs or clobs. I wouldn't know how to do it without creating a byte[] (as you did), which is just okain wrong, frankly.

  7. #7
    LovJava is offline Member
    Join Date
    Jan 2010
    Posts
    24
    Rep Power
    0

    Default

    why do u think its wrong?

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Well, loading a file up entirely when you have no processing to do on it, and all you're going to do is stream it to somewhere else, is wrong. It should simply be streamed straight out.

    I get the impression (though I could be wrong) that Hibernate doesn't easily let you do that.

Similar Threads

  1. How to make Beans Lazily-instantiating beans
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-30-2008, 10:10 AM
  2. How to make Beans Lazily-instantiating beans
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 08:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •