• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Retrieving an image from SQL Server database

 
Ranch Hand
Posts: 89
Oracle Java
  • 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
 
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?
 
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
 
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 ]
 
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
 
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
Oracle Java
  • 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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!