Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
[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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Followups here.
 
    Bookmark Topic Watch Topic
  • New Topic