Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic

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

Monty Guppy
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Report post to moderator
Followups here.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!