1

I use MySQL db for my project.I want to save data with jdbc.But there is a problem with some characters.For example ğ,ş.My connection url is below.

jdbc:mysql://localhost:3306/kutuphane useUnicode=true&characterEncoding=UTF-8 

But I am getting java.sql.SQLException: Incorrect string value: '\xC4\x9F\xC4\x9F\xC4\x9F' error.I have tried all of the methods in this site but it is not solving the problem.Even though it saves , at this time record's character is failing.Not display ğ,ş etc.Is it a mysql bug or not?

7
  • The issue is most likely in the character set of the table. Try to execute your insert in MySQL CLI and see what error you get there.
    – Norbert
    CommentedMar 27, 2015 at 21:09
  • I have tried and get no error.It is saving.
    – emreturka
    CommentedMar 27, 2015 at 21:20
  • Is the SQLException coming from an INSERT? (In utf8 encoding, hex C49F is ğ "latin small letter g with breve" - a Turkish character)CommentedMar 27, 2015 at 21:26
  • Yes it comes from insert
    – emreturka
    CommentedMar 27, 2015 at 21:30
  • 1
    "Is it a mysql bug or not?" - No, it is not a bug. You are simply trying to insert UTF-8 characters into a column that cannot accept them. As @RickJames suggested, please edit your question to show us the results of SHOW CREATE TABLE.CommentedMar 28, 2015 at 12:06

2 Answers 2

3

Incorrect string value: '\xC4\x9F\xC4\x9F\xC4\x9F'

You are trying to insert UTF-8 characters into a column that cannot accept them. You must ensure that the COLLATION (character set) of the column is compatible with UTF-8.

That column setting may have been explicitly set, or it may have just used the default setting for the table (which may or may not have used the default value for the database, which in turn may or may not have used the default value for the server).

SHOW CREATE TABLE tablename will tell you what the current settings are. If you see something like

CREATE TABLE `utf8test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `textcol` varchar(50) COLLATE latin1_general_cs DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs 

then you will not be able to insert arbitrary UTF-8 characters into textcol until you do something like

ALTER TABLE utf8test CHANGE COLUMN textcol textcol VARCHAR(50) COLLATE utf8_general_ci 
1
  • My table is UTF-8 anyway.Although it is UTF-8 I can not insert to it
    – emreturka
    CommentedApr 1, 2015 at 6:46
0

MySQL supports by default utf8 where characters are represented by 3 characters. For 4-byte characters you need to use utf8mb4 instead.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.