This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Converting from BLOB to string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Converting from BLOB to string" Watch "Converting from BLOB to string" New topic

Converting from BLOB to string

Shane Lee
Ranch Hand

Joined: Mar 19, 2005
Posts: 63
Im selecting back from oracle database a blob value which is my xml message.
My code to transform the blob to a string is:

This does work, Im just wondering if this is the most efficient/correct way of coverting the byte array to a string?
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3749

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 JDBC driver and goes whatever works. Keep in mind, string encoding can get ugly for reading blob data.

[OCA 8 Book] [Blog]
I agree. Here's the link:
subject: Converting from BLOB to string
It's not a secret anymore!