This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting a Blob to a String for display

 
Leticia Barbalho
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

It seems c ut or even ${element} is bringing some kind of problem. I have a stored blob, and when trying to retrieve it with this command, it prints me the binary value.. something like [B@496edh or stuff like that.

How should i print it for it to work? Should I use some specific tag?

thanks
[ September 09, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The evaluation of the object will be whatever its toString() method emits. If what that emits is not what you want, you will need to convert the contents of the blob (I assuming it is text) to a String before sending it to the page, or to wrap it in a bean that can emit the conversion on your behalf.
 
Leticia Barbalho
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried converting it like this:



Didn't work. The other constructor, which specifies the charset, also didn't work. Should I convert it byte per byte? How should I do it? thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know myself. At this point this has become more of a JDBC issue than a JSP issue, so I've changed the title and moved it to the JDBC forum where the blob-savvy are more likely to hang out.
 
Leticia Barbalho
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
Leticia Barbalho
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I solved my problem in other way.

That's the code I wrote:



the byte comes in, the String comes out

Thanks everyone.
 
Leticia Barbalho
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
:S ops
it only works for numbers, not for words (letters, you know)

Must keep trying.
 
Leticia Barbalho
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear, your tip won't work for me because what I actually need to convert to a String is not a Blob, is a byte[]. Maybe the title of this topic should be changed.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, why did not the String constructor work out for you?
 
Leticia Barbalho
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know. It returns me weird characters.. I tried setting some charsetNames also, but I may have used them wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic