File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Java/ SQL-Server- Saving data to an IMAGE datatype Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Reply locked New topic

Java/ SQL-Server- Saving data to an IMAGE datatype

Monty Guppy
Ranch Hand

Joined: Sep 15, 2001
Posts: 49
I have a text file whose data I convert to a bytearray and thereafter want to save the bytearray to an IMAGE datatype in a sql-server table. The intention is to let the users download this file later on from the internet.
Currently I am able to use the IMAGE datatype successfully in the above fashion for storing & retrieving PDF files (i.r. uploading a PDF file as a bytearray for uploading into the table and lateron while retrieving, I ready the bytearray with the setContentType in my servlet="application/pdf".
But, it doesn't work for the text file. I am using the following code in the servlet to download the data:
response.setContentType ("application/x-filler");
The data in the downloaded file looks like this:
The data when originally uploaded from a text file was actually:
Doe, John, E.
My question is:
- Is it possible to use IMAGE datatype for storing bytearray obtained from converting text data? Or do I have to create a separate TEXT datatype field.
- I am using opta2000 drivers for JDBC connectivity. I have observed that when I am try to upload the byte array to the IMAGE datatype, it complains if I don't have quotes around the bytearray (and the update query fails). I ultimately saved the bytearray after enclosing it within quotes. I have a feeling that this may be resulting in the data being saved as text rather than as a bytearray.
Any thoughts would be gratefully appreciated.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Followups here.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Java/ SQL-Server- Saving data to an IMAGE datatype
It's not a secret anymore!