aspose file tools*
The moose likes JDBC and the fly likes how to retrieve image from database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to retrieve image from database?" Watch "how to retrieve image from database?" New topic
Author

how to retrieve image from database?

krishna dey
Greenhorn

Joined: Mar 11, 2008
Posts: 12
Hi,
How can i retrieve image from database (in java). i am using MySQL. i have created a table which contain a column of blob type and manualy i have stored one image. after retrieving i will display it in word document.

Please help me......
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
Is this question about
  • how to retrieve the contents of a BLOB field,
  • how to create an image from a byte[] or
  • how to embed an image in a Word document?

  • What do you have so far?


    Ping & DNS - updated with new look and Ping home screen widget
    krishna dey
    Greenhorn

    Joined: Mar 11, 2008
    Posts: 12
    Actually i am retrieving data from database and generating a word file. on that word document i have to display one image. I have inserted that image manualy to the database. but i dont know how to retrieve that image. if you have any idea to solve this problem then please help me.
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 39549
        
      27
    Do you know how to execute SELECT statements? If so, you can use the getBlob method to get the data from the ResultSet.
    krishna dey
    Greenhorn

    Joined: Mar 11, 2008
    Posts: 12
    now i can retrieve the image from database. As i told that i am generating a word document. so after retrieving that image i am converting blob type to byte[] and then to string.

    however while i am generating the word domument the image is is not coming. so many characters are printing to that documents. how can i get that image.
    Tina Ma
    Ranch Hand

    Joined: Nov 29, 2007
    Posts: 198
    Look at this link....this may help you.


    Tina
    SCJP 1.4, SCWCD 1.4
    Tina Ma
    Ranch Hand

    Joined: Nov 29, 2007
    Posts: 198
    Look at this link....this may help you.

    http://www.google.com/search?q=create+MS+Word+.doc+with+Java
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 39549
        
      27
    Converting binary data like an image to a string will almost certainly corrupt the image data. Why would you do that? How are you inserting the image data into a Word document?
    krishna dey
    Greenhorn

    Joined: Mar 11, 2008
    Posts: 12
    Hi Ulf Dittmer,

    Using this code i am retreivivg and converting the image to string
    then i am using this string for word generator code. is there any other way to write image to word document?


    int len = 0;
    len = (int)(rslogo.getBlob("uftjobs_logo").length());
    byte [] data = rslogo.getBlob("uftjobs_logo").getBytes(1,len);
    for (int ii = 0; ii < len; ii++)
    {
    byte c = data[ii];
    logo = logo + (char)c;
    }
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: how to retrieve image from database?
     
    Similar Threads
    store an image to database and also retrieve
    Retrieving Image from SQL server using Java
    Save and retrieve image in derby database
    inserting image
    How can i randomly viewing image on jsp from the database