Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Feb 2004
    Posts
    12

    Unanswered: Unicode in MySQL

    Hi guys and gals

    I want to enter unicode data to MySQL. I wrote a jsp for data gathering from user. but after entering data and clicking Submit button, the data which enter to MySQL are unicode numbers. for example I enter a 4-letter word in Arabic and after clicking on submit button, the "& #1587; & #1604; & #1575; & #1605;" goes to MySQL. (I put blanks inside them for readability) What is the problem? My jsp charset is utf8. What are possiblities?

    I have mysql-4.1.1a-alpha-win with mysql-connector-java-3.0.10-stable and Tomcat 4.1.24 and also this parameter in server.xml of Tomcat, so Tomcat should connect to MySQL with UTF-8. Right? Is '& amp;' in parameter correct?

    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost/test?userUnicode=true&amp;characterEncoding=UTF-8</value>
    </parameter>

    Also my Browser (IE) encoding is UTF8.


    Thanks,
    Webgard
    Last edited by webgard; 02-18-04 at 10:35.

  2. #2
    Join Date
    Feb 2004
    Posts
    12
    hi,my problem is the same as yours.

    i think string's encoding should be convert before insert date into the mysql.
    how do you check the data in mysql?what tools?

  3. #3
    Join Date
    Feb 2004
    Posts
    12
    Hi,

    I use "Jbuilder Database Pilot" for checking data. What do u use?

    I will work on it more after holidays. I will let you know the result if I succeed and Please do the same in the case you reach some points.

    Now I have several ideas, I should test them.

    I will start server with utf8, make a clean db with utf8, and tables with utf8 and also connect using utf8, with jsp encoding utf8 and IE is utf8 too. :-) all utf8

    I will test it.

    Keep in touch
    Webgard

  4. #4
    Join Date
    Feb 2004
    Posts
    12
    hi

    i have test your case.
    it can't be see that string is chinese.it just is something like ???????;

    the jdbc driver maybe can't corresponding the mysql4.1.1
    maybe it isn't stable one.it just is my options.

    the sql is different from the older.
    you can look the following url:

    http://perlwelt.horus.at/Beispiele/M...lUnicodeMysql/

  5. #5
    Join Date
    Feb 2004
    Posts
    12
    zhu1230,

    just a note:

    When you are using JDBC drivers to connect MySQL, you should use 'UTF-8' instead of 'utf8', becasue Java can't understand utf8.

    useUnicode=true&characterEncoding=UTF-8 is correct.

    Seeing just ?????? was my first problem. I just changed utf8 to UTF-8 and it worked. seeing unicode numbers instead of unicode charactes is my second problem.

    Regards,
    Webgard

  6. #6
    Join Date
    Feb 2004
    Posts
    12
    i am very glad to see your answer!

    the mistake make me almost crazy!

    i will continue test this.thank you.

    regards
    zhu1230

  7. #7
    Join Date
    Feb 2004
    Posts
    12
    great!
    i have test the case.
    i have get the correct string.

    it is all UNICODE.

    and i have found a "bug" in the connect pool configuration which the tomcat-dos indicate.
    the following snip code is no effect about the characterEncoding,i use it with the struts.i have waste much time to test the problem with the "bug" code.



    <Resource name="jdbc/zzksDB" auth="Container"
    type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/zzksDB">
    <parameter>
    <name>username</name>
    <value>dbusername</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>dbpassword</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>com.mysql.jdbc.Driver</value>
    </parameter>
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost/zzks</value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>200</value>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>10</value>
    </parameter>
    <parameter>
    <name>username</name>
    <value>root</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>200113</value>
    </parameter>
    <parameter>
    <name>useUnicode</name>
    <value>true</value>
    </parameter>
    <parameter>
    <name>characterEncoding</name>
    <value>UTF-8</value>
    </parameter>
    </ResourceParams>

    if i use the url with


    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost/zzks?useUnicode=true&characterEncoding=UTF-8</value>
    </parameter>


    then the tomcat can't start.

    my tomcat is 5.0.jdk 1.4.2 win2000(chinese)
    mysql 4.1.1


    regards
    zhu1230

  8. #8
    Join Date
    Feb 2004
    Posts
    12
    about your problem,i have some suggestions:

    1,use the filter which can change the request's characterEncoding.
    If you want,i can give some code.

    2,don't use the server.xml connect pool,you can test to use the JSP to connect the database first.if right, we can test other effect conn-pool;

    3,change the jvm-character-encoding to UTF-8.(i don't know whether this is necessary.i can test the necessary of it.but i want that all is unicode.)

    this is all.

    regards
    zhu1230

  9. #9
    Join Date
    Feb 2004
    Posts
    12
    hi

    you said:

    -------------
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost/zzks?useUnicode=true&characterEncoding=UTF-8<

    /value>
    </parameter>

    then the tomcat can't start.
    ------

    did you use '&' in XML? it can't be understood by parser. try to change '&' to '& amp;' (without blank) and restart Tomcat and let me know the result.

    I will test your case and let you know the result..

    Regards,
    webgard

  10. #10
    Join Date
    Feb 2004
    Posts
    12
    oh,i see.i forget it.

    ALL is OK!

    i don't know why the following snip code has no effect?

    <parameter>
    <name>useUnicode</name>
    <value>true</value>
    </parameter>
    <parameter>
    <name>characterEncoding</name>
    <value>UTF-8</value>
    </parameter>


    although this condition,i have get my purpose.

  11. #11
    Join Date
    Feb 2004
    Posts
    12
    i hope the mysql4.1 have the stable version.

    regards
    zhu1230

  12. #12
    Join Date
    Feb 2004
    Posts
    12
    Hi,

    you said it worked on your box!! Now, you see unicode chars in database?? u dont see unicode numbers instead of chracters in your DB??

    I am still seeing the unicode numbers instead of unicode chars. Maybe my tool (Jbuilder Pilot) has problem. What tools are u using as browsing the database?

    regards,
    Webgard

  13. #13
    Join Date
    Feb 2004
    Posts
    12
    i input the string to db,and get the same string from db.
    then,i use the phpmyadmin to get the correct string.not numbers.


    you have set all is UTF-8?

    can you ensure?

    i am very glad to help you,i wait for your success!


    regards
    zhu1230

  14. #14
    Join Date
    Feb 2004
    Posts
    12
    zhu1230

    yeah, i can save and retrieve unicode chars. but when I see inside the DB with database Pilot, or MySQL Control Center. I see unicode numbers.

    Mmmm... I think I have no problem. Maybe Pilot and Control Center are doing the right job and i SHOULD see unicode numbers instead of uniode chars.

    BTW, thanks for your patience. I will dig more.

    Regards,
    Peyman

  15. #15
    Join Date
    Feb 2004
    Posts
    12
    yeah,i agree with you.
    can you tell me your ICQ oR msn?
    i havn't the friend about the discuss of characterencoding problem.
    if we encounter one new problem,we can talk together again.



    regards
    zhu1230

Posting Permissions

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