• Post Reply 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

converting Blob to a String for calling POST

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! can anyone please suggest how to resolve the following issue.

I have a file that is saved as BLOB in oracle database. I am reading that into a "Blob" variable. After this I need to convert the blob into string.

I need to call a servlet that only is expecting a "String" as input.

Can anyone please suggest. If you have a sample code that will be helpful.

Regards
Anoop
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure how a servlet can be expecting a String as input type for binary data (which is what you're trying to send). Maybe you can provide some more detail on this.

One way of converting binary data into a string representation is to encode with something like base-64, the output of which will consist entirely of US-ASCII characters. Of course, the receiving end (servlet) needs to be prepared to accept base64-encoded data.

The Jakarta Commons Codec library has a base-64 implementation.
 
Reddy Anoop
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My objective is to call a servlet by passing an xml file. The servlet currently takes the input xml file and returns output as xml. I will need to take this xml parse and store it into oracle table.

I have an xml file that is stored as a blob in oracle. I am reading that blob. Since servlet that is coded is not capable of dealing with blob, I need to convert it into a character stream and send it.

I am having difficulty trying to do that. Please adivise.

Regards
Anoop
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's an actual java.sql.Blob, then you can use its getBytes method to retrieve a byte[], which you can then re-format to your hearts content.
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic