This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Pad Ven
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic