3 messages in com.mysql.lists.javaRe: Dynamically set character set
FromSent OnAttachments
Paul Wallace13 Sep 2005 00:40 
Mark Matthews13 Sep 2005 05:29 
Paul Wallace13 Sep 2005 17:12 
Subject:Re: Dynamically set character set
From:Mark Matthews (ma@mysql.com)
Date:09/13/2005 05:29:28 AM
List:com.mysql.lists.java

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Paul Wallace wrote:

Hi I need to do the above, as I will not know what language/charset is being inserted in to my DB. How can I set the character set? I tried:

Statement statement = connection.createStatement(); statement.execute("SET CHARACTER SET tis620");

Paul,

That won't work with JDBC. You have to set the character set when you connect, with the "characterEncoding=..." property. You can't change it "on the fly", as the JDBC driver can't detect this, and will send data in the wrong character encoding.

...insert my thai chars..;

Is this legal? I am inserting and getting back the now infamous question marks. Setting the character set on DB build-time is fine, but I need to set it at insertion time. I have also tried appending charset on to the connection string - String conStr = "jdbc:mysql://127.0.0.1/test1?user=root&password=root&charset=tis620"; - with no result. I found both these suggestions on 'net.

In reply to your earlier posting, did you use "characterEncoding=utf-8" instead of "charset=..." (which has never been a configuration property for the JDBC driver, btw)? That should make your application work w/ utf-8 data. Maybe the following section of the JDBC manual would help here:

http://dev.mysql.com/doc/mysql/en/cj-character-sets.html

-Mark

iD8DBQFDJsY+tvXNTca6JD8RAsMZAJ9Om/mH7/WgcBZ9lGjxmFUtiztDIACggrrc 4OMgWuGiQgzirZqoG54bP34= =o8rQ -----END PGP SIGNATURE-----