Reading BLOB fileds using JAVA

hi Guys,

I have a BLOB field in Oracle table which holds the binary representation of some XML file.

Do any one of you have any idea about how to read the actual xml ( which is a string) from the BLOB field using JAVA.

Have you tried ResultSet.getBlob()? I’m not sure if the BLOB is just a byte array of the string and not an encapsulation of the string, but if so this might work:

private String readXmlFromBlob(ResultSet rs, int column) {
   Blob value = rs.getBlob(column);
   String xml = new String(value.getBytes(0, value.length());
   return xml;
}

Links:

I recently posted some ranting about getting clobs to work:
http://www.hazelsoft.com/2005/05/28/one-of-the-reasons-i-dont-like-oracle/

Should work with blobs, too.

Hi,

I tried with resultSet.getBlob(), and after coverting into byte and string, it gives the String object of byte.

So in my final String , it is actually some numbers represented as string object. I tried this earlier.

Suppose if the xml is:

<new>
Jineesh
</new>

After converting this according to your code
i get some numbers like: 2354623989862542


Hi elel1138, Clob is more easier to deal. I already have a working program for clob

If you want to start reading in and parsing XML within your Java apps its time to learn all about SAX.

Whats a little odd (to me at least) is storing xml in a db as a blob * scratches head wondering *

Probably true, but why in the world would you want to keep text data (XML) in a binary format?