• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 42027
916
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic