File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
REST with Spring (video course)
this week in the
JDBC and Relational Databases
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.
[OCA 8 Book]
subject: Converting from BLOB to string
Inserting Image into Oracle.
how to pass multiple BLOB objects to a PLSQL procedure?
Program freezes while executing an external command
Saving Japanese Characters in Oracle Blob using Java program
inputstream, string, converting
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015