Jump to content

UTF-8 encoding on storing values in database

- - - - -

  • Please log in to reply
2 replies to this topic

#1
arnes99

arnes99

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
In Java by default I have UTF-8 encoding. In MySQL I have UTF-8 encoding as well.
The problem is somewhere in between them. When I store some value that needs utf8 encoding in the database it shows question marks for letters that belong to utf8 (non ascii letters).
NOTE. MySQL table is UTF-8 because I tested it with console input and utf-8 works. Only by storing from Java into MySQL does the problem arises.

Edited by arnes99, 07 June 2011 - 10:15 AM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
The trick is to prefix the string literal with the encoding in your SQL statement. MySQL :: MySQL 5.0 Reference Manual :: 8.1.1 Strings
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
arnes99

arnes99

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts

WingedPanther said:

The trick is to prefix the string literal with the encoding in your SQL statement. MySQL :: MySQL 5.0 Reference Manual :: 8.1.1 Strings

Tried it and it didn't work. So I set all character set variables to utf8. Again it didn't work. Finally, I added this to database URL: ?characterEncoding=utf8 and it worked! So if anyone is having same problem try it. It worked for me. :pinguin:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users