my dog learned polymorphism*
The moose likes JDBC and the fly likes converting Blob to a String for calling POST Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "converting Blob to a String for calling POST" Watch "converting Blob to a String for calling POST" New topic
Author

converting Blob to a String for calling POST

Reddy Anoop
Greenhorn

Joined: Aug 22, 2007
Posts: 8
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Reddy Anoop
Greenhorn

Joined: Aug 22, 2007
Posts: 8
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
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: converting Blob to a String for calling POST
 
Similar Threads
multiple file export as zip file (using DownloadAction class in struts)
storing images in the database
string to blob-please help
blob.putBytes(long,byte[]) and BLOBs
Data Encapsulation