Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to retrieve image from database?

 
krishna dey
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
     
    krishna dey
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Rancher
    Posts: 42969
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 198
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Look at this link....this may help you.
     
    Tina Ma
    Ranch Hand
    Posts: 198
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Look at this link....this may help you.

    http://www.google.com/search?q=create+MS+Word+.doc+with+Java
     
    Ulf Dittmer
    Rancher
    Posts: 42969
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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;
    }
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic