Mysql and java Arabic text problem

Discussion in 'MySQL' started by Mizyan, Mar 16, 2011.

  1. #1
    Hello, i have a problem with using a java application with MySQL database, i can insert arabic text and read it in mysql ( i changed the charset and encoding for database ), but in the java application i can only read it if it is arabic but when i change a text into arabic (even if it was originally in arabic ) it looks and saves in the database like this: ??????. I thought that if mysql is able to write and read arabic normally then it is a problem of query statements in the java application. i think i should put something there.
    Can anyone help me solve this problem, i really need help with this one. Thanks for all help.
     
    Mizyan, Mar 16, 2011 IP
  2. Martin K

    Martin K Active Member

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    My advice is to use UTF-8 it's universal encoding. And run SET NAMES 'utf8'; after connecting to DB:
    Make sure you back up the database
     
    Martin K, Mar 16, 2011 IP
  3. Mizyan

    Mizyan Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well, i am actually using UTF-8 in the database, but this "set names utf8" i don't know where to put it, i mean : "mysql_query('SET NAMES utf8', $link);" this is a PHP code right?
    but where can i use it in a java application.
     
    Mizyan, Mar 16, 2011 IP
  4. Mizyan

    Mizyan Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If it helps the select statement in the java application is "select * from tablename where id=....." , note that the id is a string but in English. But when i use the update statement to write Arabic language, the text becomes ?????. According to what you said Martin i need to determine the encoding after connecting to the database. but what is the code for this and where to put it in a java application.
     
    Mizyan, Mar 17, 2011 IP
  5. Martin K

    Martin K Active Member

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    I have no idea why you write php in javascript. However, you have somewhere a connection to the database find it and put this on the next row, its possible the connection to be in external file. the connection is like mysql_connect('host', 'user', 'password'); Use ctrl+F to search for "mysql_connect"

    Instead SET NAMES, you can use
    or to see the current encoding use
     
    Last edited: Mar 18, 2011
    Martin K, Mar 18, 2011 IP
  6. Mizyan

    Mizyan Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I am not using javascript, i am using a java application.
    But thanks for the help, i already found the solution for it. It's the same concept, i should define the encoding as utf8 after connecting to the database but the code in java is different.
     
    Mizyan, Mar 18, 2011 IP
  7. Mohamed_fci

    Mohamed_fci Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    can you tell me how you did as i suffer from the same problem but please quickly :)
     
    Mohamed_fci, Dec 15, 2011 IP
  8. Mohamed_fci

    Mohamed_fci Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    can you tell me how you did as i suffer from the same problem but please quickly :)
     
    Mohamed_fci, Dec 15, 2011 IP
  9. Mizyan

    Mizyan Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    First you have to set the database encoding to "UTF-8" and collation to "UTF8_general_ci"
    Then when connecting to the database in the java code use this "jdbc:mysql:localhost/Database1?useUnicode=true&characterEncoding=utf8".
     
    Mizyan, Dec 16, 2011 IP