Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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: 43027
76
  • 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: 43027
76
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic