wood burning stoves 2.0*
The moose likes JDBC and the fly likes Retrieving an image from SQL Server database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Retrieving an image from SQL Server database" Watch "Retrieving an image from SQL Server database" New topic
Author

Retrieving an image from SQL Server database

Nidhi Singhal
Ranch Hand

Joined: Sep 19, 2004
Posts: 89

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

Joined: Aug 15, 2004
Posts: 2874
It is not a servlet specific question, though.
Could you please show up your code?
Naveen Mishra
Ranch Hand

Joined: Nov 20, 2005
Posts: 75
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

Joined: Nov 10, 2005
Posts: 77
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

Joined: Mar 06, 2001
Posts: 13459

Moving this to the JDBC forum.

Dave
payal agrawal
Ranch Hand

Joined: Oct 11, 2005
Posts: 44
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

Joined: Sep 19, 2004
Posts: 89

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving an image from SQL Server database