• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading & Updating SQL Server Image type  RSS feed

 
Mitchell Baron
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to create a Java method that somehow reads a SQL Server image type and returns either a blob, byte[] or whatever else would make sense so that I can display the image on a web page.

I have seen other posts about this but am still not sure how to get this to work.

Here is a small example of trying to get the image. It does not have to return a byte type, just whatever would work for displaying the image in a jsp page. I also am not sure how to prevent issues if the image column is null.



Any suggestions?

Many thanks!

Mitchell
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of storing the image itself why not store a path to the image?
 
Mitchell Baron
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have a choice unfortunately because the images already are stored in the database otherwise I gladly wouldn't have done that. Is there an effective way to extract them with Java/JSP?
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried writing that array of bytes to a file (with a suitable name denoting the type of image, JPG or PNG or whatever)? Does that produce a usable image file?
 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On your question about how to prevent issues if the column is null, I do this type of thing:


In other words, I always check if the column is null before deciding how to process it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!