Does jdbc support persian language

2019-07-11 20:04发布

问题:

I designed a java desktop application using jdbc technology to connect to mysql database. But when I want to store a data in my db which is in persian language it saved like some ????

I tried creating the database with both

CREATE DATABASE 'db' CHARACTER SET 'utf8';

and

CREATE TABLE  `Table1` (
[...]) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

I tried every other COLLATEs but they seem not working properly.

What should I do?

回答1:

Make sure the driver properties are set. Check that useUnicode is true, characterEncoding is "UTF-8". I assume you are using the Connector/J JDBC driver.



回答2:

Refer to this answer. A brief version of what the answer says is that you should add

?useUnicode=true&characterEncoding=UTF-8

To the end of JDBC connection URL. For example:

jdbc:mysql://localhost:3306/db_name?useUnicode=yes&characterEncoding=UTF-8