Results 1 to 7 of 7
  1. #1
    litpuvn is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default encoding > java, javamail and mysql

    Hi All,

    I made a program read content from database and send it over the net through email (which i use javamail).

    The problem is that if the content has international character, then its content in the mailbox, like google, (after i received) is not correctly decoded.

    MySQL setting is:
    character set connection: utf8
    character set server: utf8,
    character set results: utf8

    I also added to the java application:
    System.setProperty("file.encoding", "utf8");

    If i use a php program to see the content in my database, it is correctly displayed all international characters.

    For the javamail, i am quite sure i have encoded with utf8, example:
    msg.setSubject(to.subject, "UTF-8");
    msg.setDataHandler( new DataHandler(bodyContent, "text/html; charset=\"UTF-8\""));

    If i put the content as a constant storing international chars in the code, then i received email in my mail box correctly decoded.

    Do you see any reasons why the content in my mail box is not correctly displayed if i read it from database and send over through javamail?

    Thank you for your kind help,

    -Hoang Long

  2. #2
    litpuvn is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    i found that if i use java to read the content from database and write to a file with unicode encoding, the content is not readable as well. I am confusing why the php application (just sql query and then render the result) can display correctly.

    i did specify unicode connection already.

  3. #3
    litpuvn is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    Oooops, finally i found that it is a bug of java. A possible workaround is to read the content as byte array then convert to the unicode encoding.

    Can't get unicode with ResultSet.getString() - Database Forum

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,085
    Rep Power
    20

    Default

    Since that appears to be a bug in a version of the sql server driver I doubt it's necessarily the same problem.

    What driver are you using?
    Have you tried a different driver, or even a newer version of the one you have?

  6. #6
    litpuvn is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    good guess, i was using jdk 1.6 and mysql-connector-java-3.0.17-ga.zip; i tested with the latter version of the connector which is mysql-connector-java-5.1.13.zip and it appeared the same issue. Nice to know this issue, and very strange when Oracle didn't resolve this issue.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,085
    Rep Power
    20

    Default

    That link you posted was for MS SQL Server, not Oracle.

    To be honest, we don't have an issue with MySQL (just realised that's our db here), and we have translations stored in it in several languages that require UTF8.

    I have to say I suspect it's something other than the driver then...I think ours is 3.1.14

Similar Threads

  1. javamail > subject encoding issue?
    By litpuvn in forum Advanced Java
    Replies: 7
    Last Post: 10-25-2010, 11:37 AM
  2. MySQL/JDBC Mysql query output
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-13-2009, 01:57 AM
  3. Character encoding in Java (Linux to Windows)
    By BeholdMyGlory in forum New To Java
    Replies: 2
    Last Post: 01-16-2009, 06:24 PM
  4. How to specify character encoding in JavaMail?
    By jfcup in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 10-24-2008, 07:55 PM
  5. Some help with encoding...
    By nm123 in forum Networking
    Replies: 0
    Last Post: 04-15-2008, 12:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •