Jalal Sordo
Jalal Sordo

Reputation: 1685

How to change JDBC Encoding to support French accent characters

im having a problem with fetching data from Mysql 5.1 using JDBC(mysql-connector-java-5.1.18-bin.jar).

my insert into statement goes like this:

    INSERT INTO Categories  VALUES ('01','Matières premières');

and the output from Netbeans terminal and Swing Interfaces goes like this :

    MatiŠres premiŠres

i think that I need to specify the encoding parameters.

can you please help.

p.s: the OS is Windows 7 French.

this is my url to the database in class connection :

    DriverManager.getConnection("jdbc:mysql://X.X.X.X:XXXX/XXXX?useUnicode=yes&characterEncoding=UTF-8","XXXX","XXXX");

Upvotes: 1

Views: 2579

Answers (2)

Ben
Ben

Reputation: 318

you have to set encoding to ISO-8859-1 with System.setProperty("file.encoding", "ISO-8859-1")

Upvotes: 0

Denys Séguret
Denys Séguret

Reputation: 382274

Two solutions :

  • the sanest one : set your tables to use as collation "utf8-general-ci" and set mysql to use the same collation for connections. So you won't have any problem and you won't need to specify anything when connecting using jdbc.

  • another one, barely acceptable now but possible : determine what's the collation of your tables and use it to configure your connection in JDBC as described here : http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-charsets.html . But you must know what's the encoding of your tables (as you don't know it and if you're in France it may be Latin1).

To determine or change the encoding of your tables you may use any mysql admin tool. Be sure to be coherent for the tables and connection.

Upvotes: 1

Related Questions