开发者

mysql java versus c program, difference in characters stored

开发者 https://www.devze.com 2022-12-10 11:33 出处:网络
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 d

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消