Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: inserting utf8 data into DB

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    25
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default inserting utf8 data into DB

    Hello Everybody
    I'm using MySQL and I created database with UTF8_general_ci format
    My problem is when I 'm inserting data from My Application and then retrieve data it looks like "?a?"

    query="INSERT INTO app.employee(`ID`, `NAME`, `ADDRESS`, `PHONE`) VALUES (5, 'şöhratyň', 'street', '555555');";
    statement.execute(query);
    when I retrieve data it looks like this
    5 ?öhraty? street 555555

    but when I inserted that data from cmd its OK
    I have tried to set connections property to utf 8 but it doesn't work too

    please help
    regards


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: inserting utf8 data into DB

    What encoding is your JVM using? System.getProperty("file.encoding") should tell you. Problems like these are usually caused by mismatched encodings on your platforms.

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    25
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: inserting utf8 data into DB

    Quote Originally Posted by Sean4u View Post
    What encoding is your JVM using? System.getProperty("file.encoding") should tell you. Problems like these are usually caused by mismatched encodings on your platforms.
    My JVM using UTF-8 encoding

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    17
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: inserting utf8 data into DB

    Look this site :
    Unicode/UTF-8-character table

    for example :

    String string = "abc\u5639\u563b";
    System.out.println(string);

  5. #5
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: inserting utf8 data into DB

    On the offchance it helps, I found an old config file from MySQL from a defunct Java project where I had similar problems. You need to specify utf8 for both the database and client connections. Here are the relevant parts from my old my.cnf:

    [client]
    default-character-set=utf8
     
    [mysqld_safe]
    collation_server=utf8_unicode_ci
    character_set_server=utf8

    I guess you don't need telling that changing the platform encodings won't 'fix' problems in existing data? You'll almost certainly have to empty your tables and repopulate them after an encoding change.

  6. The Following User Says Thank You to Sean4u For This Useful Post:

    serdar (August 6th, 2011)

Similar Threads

  1. [SOLVED] Inserting date into database
    By mithcool in forum Java Theory & Questions
    Replies: 2
    Last Post: July 16th, 2011, 02:54 AM
  2. Java Newbie - Sorted Linked List not inserting properly - please help!
    By bubbleboy in forum What's Wrong With My Code?
    Replies: 20
    Last Post: June 17th, 2011, 12:48 PM
  3. Beginner Needs Help Inserting row to table
    By MoniD in forum JDBC & Databases
    Replies: 5
    Last Post: March 10th, 2011, 02:15 PM
  4. Check for duplicates before inserting into database
    By igor0203 in forum JDBC & Databases
    Replies: 1
    Last Post: December 2nd, 2010, 09:04 AM
  5. Inserting Image Help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 22nd, 2010, 01:50 PM