This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes SQL Server image datatype Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Server image datatype" Watch "SQL Server image datatype" New topic

SQL Server image datatype

Dan Eichler

Joined: Dec 01, 2011
Posts: 6
I'm a little newish to java, but really new to sql server and datatype image.

I am trying to extract files from the database and store them locally on the computer. I have retrieved the image contains from the column with rs.getBlob, and have saved them to the system with the following code:

BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fileName));
bos.write(blob.getBytes( 1, (int) blob.length()), 0, (int) blob.length() );

This does save the file, but I can't open the file no matter what I change the extension to. The kicker is that I don't know what each file is suppose to be, the database does not contain the names of the files either.

Dan Eichler

Joined: Dec 01, 2011
Posts: 6
So it ended up being the way the data has been stored into the database. It's converted to another proprietary format. I have tested my code on another table in the database that has pdf's stored as blobs and those work fine.

I agree. Here's the link:
subject: SQL Server image datatype
jQuery in Action, 3rd edition