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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Retrieving an image from SQL Server database" Watch "Retrieving an image from SQL Server database" New topic

Retrieving an image from SQL Server database

Nidhi Singhal
Ranch Hand

Joined: Sep 19, 2004
Posts: 89


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....

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...
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

Chidanand Chauhan

[EDIT - Code tags added by Dave]
[ November 28, 2005: Message edited by: David O'Meara ]
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Moving this to the JDBC forum.

payal agrawal
Ranch Hand

Joined: Oct 11, 2005
Posts: 44
Look at the URL below:

How to store/retrieve image to/from SQLServer
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...

I agree. Here's the link: http://aspose.com/file-tools
subject: Retrieving an image from SQL Server database
Similar Threads
how to retrieve image from database?
Images in Microsoft SQL server 2005
Displaying an image from byte[] into JSP
reducing load on server
Retrive column of type 'image'