• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving an image from SQL Server database

 
Nidhi Singhal
Ranch Hand
Posts: 89
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am storing an image in the SQL Server database, but facing a problem in retrieving it back.
I am using PreparedStatement and getBinaryStream() method to retrieve an image as InputStream. But after that, I am unable to convert it from the InputStream to a byte array.
If anybody know the solution, please letme know....

Thanks,
Nidhi
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not a servlet specific question, though.
Could you please show up your code?
 
Naveen Mishra
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nidhi,
go through the following link and ur problem is no more...
http://swforum.sun.com/jive/thread.jspa?threadID=46410&tstart=0
 
Chidanand Chauhan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the below code would fullfill your problem.


//code for the conversion of the image into the bytes form




Thanks
Chidanand Chauhan



[EDIT - Code tags added by Dave]
[ November 28, 2005: Message edited by: David O'Meara ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the JDBC forum.

Dave
 
payal agrawal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the URL below:

How to store/retrieve image to/from SQLServer
http://www.java-tips.org/content/view/203/29/
 
Nidhi Singhal
Ranch Hand
Posts: 89
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you for the help.

Chidanand, I have used your code and it's working perfectly. Thanks...

Earlier I was trying to write the bytes to a file...but it was too slow..
but on using imageio as in your code.... it's working quite fast...
thanks...

Nidhi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic