File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes I can't print accented caracters Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "I can Watch "I can New topic
Author

I can't print accented caracters

Rog�rio J. Ribeiro
Greenhorn

Joined: Jan 27, 2005
Posts: 11
I'm from Brazil-Goi�nia

see a situation:

I can not print accent caracter, they come with interrogation mark.....

see the code:

Blob blob = temp.getBlob("conteudo");
InputStream in = blob.getBinaryStream() ;
byte b = 0;
while (b != -1)
{
b = (byte)in.read();
out.print((char)b);
}

see the print: interrogation signal

Mostrar ?cones Pequenos no Menu Iniciar:I Esta op??o determina como os ?cones ser?o exibidos dentro do menu Iniciar.


I'm used a Firebird database.....

Thanks....
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
How are you writing into the Blob? If the Blob is a UTF-8 encoding, then you'll need to decode using UTF-8 as well (or whatever character set was used to encode). What you're doing is treating each byte as a character, but chars in Java at 2 bytes (Unicode).

Can you post the code that creates the Blob? Or, if it's created outside of Java, can you find out what encoding was used?
Rog�rio J. Ribeiro
Greenhorn

Joined: Jan 27, 2005
Posts: 11
CREATE TABLE SUBTOPICO (
ID_SUBTOPICO INTEGER NOT NULL,
ID_TOPICO INTEGER,
DESCRICAO CHAR(100),
CONTEUDO BLOB SUB_TYPE 1 SEGMENT SIZE 80,
ID_PRODUTO INTEGER,
NUMSUBTOPICO INTEGER
);
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Sorry if I wasn't clear. I meant to ask how are the rows containing the BLOBs inserted? Do you use JDBC to insert rows or some other application? If it's Java, then the code must be encoding the 2-byte-character String into a 1-byte array. Typically this is done with UTF-8 (or a modified form), but there are other options.

If some other program (a SQL script you run through isql/sqlplus or an ASP or a data feed from some other database), then you need to figure out how that program is encoding the string.

This Google search will bring up some good information on UTF-8 character encodings. Here's another one about ISO-8859 Latin. It's a tricky subject, but the bottom line is that the encodnig and decoding algorithms must match or you'll get garbage.

A metaphor would be writing a JPEG to disk (pixels -> byte array) and then trying to read it as a GIF (byte array -> pixels). Since the way the "->" is done in each method differs, you won't get an image back.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: I can't print accented caracters
 
Similar Threads
A flatland puzzle
Convert BLOB-Field to String
How to upload a byte array into BLOB column?
java.sql.SQLException: Unsupported feature
How to print a BLOB