aspose file tools*
The moose likes JDBC and the fly likes Converting a Blob to a String for display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Converting a Blob to a String for display" Watch "Converting a Blob to a String for display" New topic
Author

Converting a Blob to a String for display

Leticia Barbalho
Ranch Hand

Joined: Sep 02, 2005
Posts: 37
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

Joined: Jan 10, 2002
Posts: 61434
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Leticia Barbalho
Ranch Hand

Joined: Sep 02, 2005
Posts: 37
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

Joined: Jan 10, 2002
Posts: 61434
    
  67

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

Joined: Sep 02, 2005
Posts: 37
Thank you very much
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

This may be of help.
Leticia Barbalho
Ranch Hand

Joined: Sep 02, 2005
Posts: 37
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

Joined: Sep 02, 2005
Posts: 37
:S ops
it only works for numbers, not for words (letters, you know)

Must keep trying.
Leticia Barbalho
Ranch Hand

Joined: Sep 02, 2005
Posts: 37
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

Joined: Jan 10, 2002
Posts: 61434
    
  67

In that case, why did not the String constructor work out for you?
Leticia Barbalho
Ranch Hand

Joined: Sep 02, 2005
Posts: 37
I don't know. It returns me weird characters.. I tried setting some charsetNames also, but I may have used them wrong.
 
wood burning stoves
 
subject: Converting a Blob to a String for display