• 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

Parsing BLOB datatype

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I need help/suggestion on how to resolve the following issue.
I need to read an xml file stored in as BLOB in an oracle table. I am able to read the file. I am stuck after this because, I am calling another java program to parse by passing in an XML file. Since I am not sure how to convert the BLOB to an xml file, I am getting no where. Any suggestions/help is greatly appreciated.
Here is what I need to do.
1. Read BLOB data type from xml
2. Convert the BLOB into an xml file and call the parser program with this
xml file as the parameter.

Regards
Anoop
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well first thing you need to do is convert the Binary Data into a String. Do you have the code that put the XML into the BLOB? Is it on the same platform?

When you call the getBytes() method of a string, you use the default character encoding for the platform the JVM is running on. You do have the option of passing a Character encoding to the getByte() method to specify how the String is converted into Bytes. Check out the JavaDoc for getBytes() method on java.lang.String for how to do this.

Once you figure out what encoding, you then need to gather your bytes and create a String. You can do this in a loop that reads the ByteInputStream into an array. Then you can construct a string that contains your XML with the String(byte[] bytes, String charsetName) constructor.

After you have your XML in a string it is easy to open a FileWriter and write the String to the Writer.


Originally posted by Reddy Anoop:
Hello,

I need help/suggestion on how to resolve the following issue.
I need to read an xml file stored in as BLOB in an oracle table. I am able to read the file. I am stuck after this because, I am calling another java program to parse by passing in an XML file. Since I am not sure how to convert the BLOB to an xml file, I am getting no where. Any suggestions/help is greatly appreciated.
Here is what I need to do.
1. Read BLOB data type from xml
2. Convert the BLOB into an xml file and call the parser program with this
xml file as the parameter.

Regards
Anoop

 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In fact you don't need to create a String at all. Just write the binary stream that you can get from Blob object to a FileOutputStream. That will preserve the encoding of the XML data (assuming that it was correctly written to the database in the first place).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic