A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Converting from BLOB to string
Joined: Mar 19, 2005
Feb 25, 2009 19:00:31
Im selecting back from oracle database a blob value which is my xml message.
My code to transform the blob to a
blob = result.getBlob(1); byte b = blob.getBytes(1, (int) blob.length()); ByteArrayInputStream inputStream = new ByteArrayInputStream(b); Reader r = new InputStreamReader(inputStream); StringWriter sw = new StringWriter(); char buffer = new char; for (int n; (n = r.read(buffer)) != -1; ) sw.write(buffer, 0, n); str = sw.toString();
This does work, Im just wondering if this is the most efficient/correct way of coverting the byte array to a string?
Joined: Oct 23, 2005
Feb 25, 2009 20:41:05
Some drivers support getString() on blobs although its risky to use because of encoding. In short, blob code is never that pretty. In your case, it does seem a little long. There's a number of examples available via Google:
I'm recommend trying the simplest one with your
driver and goes whatever works. Keep in mind, string encoding can get ugly for reading blob data.
Down Home Country Coding with Scott Selikoff
subject: Converting from BLOB to string
Program freezes while executing an external command
how to pass multiple BLOB objects to a PLSQL procedure?
inputstream, string, converting
Inserting Image into Oracle.
Saving Japanese Characters in Oracle Blob using Java program
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014