It's not a secret anymore!
The moose likes Beginning Java and the fly likes Reading & Updating SQL Server Image type Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Reading & Updating SQL Server Image type" Watch "Reading & Updating SQL Server Image type" New topic
Author

Reading & Updating SQL Server Image type

Mitchell Baron
Greenhorn

Joined: Jun 09, 2008
Posts: 6
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

Joined: Jan 01, 2007
Posts: 333
Instead of storing the image itself why not store a path to the image?
Mitchell Baron
Greenhorn

Joined: Jun 09, 2008
Posts: 6
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
Bartender

Joined: Oct 14, 2005
Posts: 16480
    
    2

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

Joined: Nov 11, 2003
Posts: 109
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: Reading & Updating SQL Server Image type
 
Similar Threads
Upload Image to SQL Server Image type
Display SQL Server Image Data Type
doubt in creating connections..
CachedRowSet giving "SQLException" when using nextPage( ) method on it.
Connection Pooling samples