*
The moose likes JDBC 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
Reply locked New topic
Author

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:
[B@2dce4f48
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.
Thanks
Jim Yingst
Wanderer
Sheriff

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


"I'm not back." - Bill Harding, Twister
 
Consider Paul's rocket mass heater.
 
subject: Java/ SQL-Server- Saving data to an IMAGE datatype
 
Similar Threads
PDF generate using jasper reports
Displaying an image from byte[] into JSP
Cache file(pdf) in user's computer using Servlet-Cookie, or Session
Write an Image From Servlet
Document Retrival from database.