views:

45

answers:

1

Hello,

I have two programs- First one being a C program that writes in to mysql database. Second is a java program that reads the data from mysql database. The C program reads list of files in a particular directory and inserts the file names in DB. The Java program reads these rows and tries to do some file processing using these file names.

A particular file name contains a long dash '–' character. This fileName is read from DB by the java program. But when it tries to open the File on filesystem for this entry, the file names won't match.

When I read the file name (containing the '–' character) directly from file system using Java, the bytes for '–' character is shown as [-30 -128 -109]. Whereas the bytes shown when Java reads the fileName from DB (fileName dumped by C program), the bytes for '–' character is shown as [-61 -94 -30 -126 -84 -30 -128 -100] in Java.

Is this something to do with the Charset used by C program to put entried in to mysql?

Please help..

Thanks,
-Keshav

+2  A: 

Java strings consist of Unicode characters, not bytes. So the problem may be that either

  • The database has the string added in one encoding, but thinks it's another
  • The Java app is interpreting the database's output incorrectly in characters
  • The filesystem encoding isn't what the Java app thinks it is.

How did you enter the strings into the database? What is your table definition? What connection encoding are you using on the client applications?

Normally it's best for your sanity to use utf8 for everything (Table definition & connection encoding). If you're not doing this, you'll probably end up breaking things in some way.

MarkR
Solved the problem by enforcing connection encoding to UTF8 for all incoming client connections to Mysql server.
Keshav