File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes How to convert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to convert "java.sql.Blob" object to "java.sql.Clob" object?" Watch "How to convert "java.sql.Blob" object to "java.sql.Clob" object?" New topic

How to convert "java.sql.Blob" object to "java.sql.Clob" object?

Pad Ven
Ranch Hand

Joined: Apr 29, 2005
Posts: 38
Hi all,
Does anyone in this forum know how to convert "java.sql.Blob" object to "java.sql.Clob" object? The table field is BLOB and we could not negotiate with DBA to change it to CLOB, but we do want to convert it to CLOB. I initially tried converting the BLOB to bytes array and then bytes array to string, but this works only BLOB is actually readable string. Does anyone know a standard way to convert the java.sql.Blob object to its Clob equivalent in a systematic way?

Thanks and regards,
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
Well, binary data really isn't character data, so storing it as such is going to be a bit of a hack. An easy way to convert binary data into character data would be to base-64 encode it (the Apache Commons Codec library can do this). Not only will that give you characters, but those characters will exclusively be ASCII, so there's never a problem with having to deal with Unicode or other encodings.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32815

Originally posted by Padmanabhan Venkitasubramanian:
The table field is BLOB and we could not negotiate with DBA to change it to CLOB,

Why does the DBA not want it to a CLOB? Addressing this may be more beneficial than coming up with a hack. And it's easier to change the type now (or add a column or some logical workaround) rather than later.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: How to convert "java.sql.Blob" object to "java.sql.Clob" object?
It's not a secret anymore!