2

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?

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
Ahmad Vatani
  • 1,570
  • 4
  • 20
  • 33

2 Answers2

0

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.

brettw
  • 10,094
  • 2
  • 38
  • 55
  • yes I'm using JDBC Connector driver,but excuse me where can i change this settings?? – Ahmad Vatani Nov 16 '13 at 19:29
  • I Use this codes: Class.forName("com.mysql.jdbc.Driver"); DriverManager.getConnection("jdbc:mysql://localhost:3306/", USERNAME, PASSWORD); – Ahmad Vatani Nov 16 '13 at 19:37
  • Please, just read the documentation for the [Connector/J](http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html) driver. You can add those properties to the connection URL. – brettw Nov 16 '13 at 21:55
  • I found the solution as you see: DriverManager.getConnection("jdbc:mysql://localhost:3306/ictrc_db?characterEncoding=UTF-8", USERNAME, PASSWORD); – Ahmad Vatani Nov 17 '13 at 06:14
0

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
Community
  • 1
  • 1
Cid
  • 2,466
  • 4
  • 24
  • 36