Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes BLOB to String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "BLOB to String" Watch "BLOB to String" New topic
Author

BLOB to String

Roshan Rama
Greenhorn

Joined: Feb 28, 2009
Posts: 2
Hi all,

Is it possible for someone to help me convert a BLOB to a String or readable text?
i am recieving this data from a queue.

Thanks in advance
Samuel Behrman
Ranch Hand

Joined: Oct 02, 2009
Posts: 49
Direct conversion is not possible without using some UDF, but you can extract text using SUBSTRING function:

DECLARE VARIABLE c1 VARCHAR(32000);
SELECT SUBSTRING(blob1 FROM 1 FOR 32000) FROM t1 INTO c1;

Please note that maximum length for VARCHAR is 32767 bytes (which might be less characters in multi-byte character sets like UTF8).

Various database access layers also have ability to retrieve BLOB data as string. For example, in PHP you could use:

$row = ibase_fetch_assoc($qry, IBASE_TEXT);

This automatically converts all textual BLOBs to VARCHARs, so you don't need to fetch blobs writing specific PHP code.


RAQ Report: Web-based Excel-like Java reporting tool.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

A BLOB (binary large object) is binary data, so it could lead to problems when you convert it to text. If it should always be text a CLOB (character large object) is a better choice.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38478
    
  23
Sounds like something database-related, so I shall move it to our databases forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BLOB to String