aspose file tools*
The moose likes JDBC and the fly likes How to convert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
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
Author

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,
TVP
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
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.


Ping & DNS - my free Android networking tools app
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30957
    
158

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert "java.sql.Blob" object to "java.sql.Clob" object?