views:

182

answers:

3

Mysql's environment is following:

character_set_database="big5"

And when I send a SQL which contains tranditional Chinese

(such as "select * from a where name = '中')

from jdbc to mysql database, it will throw the following exception:

Illegal mix of collations (big5_chinese_ci,IMPLICIT), (latin1_swedish_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE) for operation ' IN ''

How can i solve this ?

But we need to do that between oracle and mysql, and when my program get the data from oracle(it's encoding is ISO-8859-1) and pass it into the SQL statement in JDBC, it will have such problem, but i can't change the collation of oracle. How to solve this? Why JSP can't solve this automatically ?

I have tried to convert but Chinese characters can not be saved into Latin1 character set. might this cause the problem ?

+1  A: 

Check your collations. The database itself can have one collation and the tables another one totally different. If you mix collations from two tables, you get this error.

Also, the swedish collation seems to be the default for databases (have no idea of why).

The Disintegrator
what is the collations used for ?
MemoryLeak
so you mean this a database setting issue, but not because the encoding in my jsp code have problem ?
MemoryLeak
In your question you only where talking about MySQL. But, yes, it's a database issue. A collation is a set of rules for comparing characters in a character set http://dev.mysql.com/doc/refman/5.1/en/charset-general.htmlModify all your tables so they all share the same collation. It's only needed between interacting tables, but better safe than to sorry.
The Disintegrator
haven't read the jdbc part. But the answer still the same.
The Disintegrator
But we need to do that between oracle and mysql, and when my program get the data from oracle(it's encoding is ISO-8859-1) and pass it into the SQL statement in JDBC, it will have such problem, but i can't change the collation of oracle.How to solve this?Why JSP can't solve this automatically ?
MemoryLeak
You need to use the same collation in both ends, or at least, translate the encoding in JSP. JSP shoud have a function for this.
The Disintegrator
A: 

What's your encoding in your java project side? Did you make sure that it's big-5 too?

Winston Chen
They are utf-8, i think.
MemoryLeak
A: 

JSP can't solve the problem. How should JSP know, what you want?

Do you make any encoding-transformation in your JSP or do you just put the oracle-data into the mysql-database?

In generaly it is important to have the same encoding in your script, your tables and very important in the connection to the database.

Joerg
have tried to convert but Chinese characters can not be saved into Latin1 character set. might this cause the problem ?
MemoryLeak
You can't convert chinese characters into Latin1, you can try to convert it into utf, maybe that this will work, but the best way is, to have in every part of your system the same encoding, otherwise you will run into trouble.
Joerg
AND don't forget to use the right character set for the connection to the db:http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html
Joerg