File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Setting up Character set for mysql table and java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Setting up Character set for mysql table and java" Watch "Setting up Character set for mysql table and java" New topic
Author

Setting up Character set for mysql table and java

Gabor Beke
Greenhorn

Joined: Jul 11, 2012
Posts: 16
Hi guys!

I'm looking for a solution for setting up my mysql database table for Hungarian character set. My problem is that when I insert data to the database (Mysql) some letters turns into a "?" mark. When I add data into database directly through for example with navicat its working fine.

I have problems with the following hungarian letters:

"ö", "Ő", "ű" ,"Ű"

All these letters are turning into ? when I insert the data through my java program. So please can you help me how to set up this correctly? UTF8 and latin2 charsets contains the hungarian charsets I guess but I still dont know how to set it up in my java.

Here is my create table syntax from my java program:



Also what would happen if I would replace "ö", "Ő", "ü" "Ű" with the ASCII code for "ö", "Ő", "ü", "Ű" ? after insert into db it would be viewed as letters or it whould show only the ASCII code? and vice versa.

So far I tried to set table's char set, field char sets but I guess its not enogh, something still missing from java side?

I want to make table with the right settings so users dont have to mess with it.

Thanks.
Gabor Beke
Greenhorn

Joined: Jul 11, 2012
Posts: 16
Nevermind I found it out by myself.



Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 905
    
    5
Gabor Beke wrote:Nevermind I found it out by myself.


As a sign of courtesy you could post the solution for the sake of those people who come across this thread with, say, search engines and hope to find useful information.

Gabor Beke
Greenhorn

Joined: Jul 11, 2012
Posts: 16
Here are the solution:

Setting up the mysql connection: (my server is located on localhost for testing)




put this line right after the question mark. Sorry about this code blocks have character limits :-/





mysql table create example with hungarian charset:




After these you will have no more problems with any hungarian letters Have a nice day
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Thank you for quoting it. That solution would be useful in français or español or bøkmål (Norwegian), too
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

If I recall correctly, my solution was just to configure MySQL to use UTF-8 as its default character set when I installed it. (That did require exporting all of the data, reinstalling MySQL with the "use UTF-8" option, and then reimporting all of the data.) I don't have anything in my connection string which mentions Unicode or any charset at all, and I don't have any SQL code which mentions charsets either.

And I do have place names from Slovakia and Iceland in my tables, so I have pretty good test data. Haven't been to Hungary yet but I would like to get there one day.
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 905
    
    5
When I played around a little with mysql and Java, I also set the database generally to utf8, and that was it.
Latin2 covers only a limited choice of characters anyway.

"árvíztűrő tükörfúró" is a nice test case containing all accented Hungarian vowels: "floodresistant mirrordrill" - it might come in useful these bad weather stricken days ;-)

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8404
    
  23

Ivan Jozsef Balazs wrote:"árvíztűrő tükörfúró" is a nice test case containing all accented Hungarian vowels: "floodresistant mirrordrill"...

I love those things. There's an old Polish tongue-twister my dad taught me when I was about 6 that's used to teach kids how to roll their 'r's properly.
I still remember how to say it, but unfortunately, having not learned much Polish, only know that the opening phrase translates as: "the black cow chews grass".

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 905
    
    5
Winston Gutkowski wrote:There's an old Polish tongue-twister my dad taught me when I was about 6 that's used to teach kids how to roll their 'r's properly.
I still remember how to say it, but unfortunately, having not learned much Polish, only know that the opening phrase translates as: "the black cow chews grass".



Would you mind putting it down? Maybe somebody speaking (actually reading...) Polish would chime in.

Dzin dobryn anyway!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

That would be "czarna trawa krowa przeżuwa" according to Google Translate. Doesn't seem much like a tongue-twister to me (at least no more so than any other Polish phrase) but then my experience with Polish is limited to ordering in a couple of restaurants.
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 905
    
    5
In Hungarian we have got our tongue-twister to roll the r's without much sense actually.

Répa, retek, mogyoró: korán reggel ritkán rikkant a rigó.

Carrot, radish, hazel: the throstle cries seldom in the early morning.
Gabor Beke
Greenhorn

Joined: Jul 11, 2012
Posts: 16
Paul Clapham wrote:If I recall correctly, my solution was just to configure MySQL to use UTF-8 as its default character set when I installed it. (That did require exporting all of the data, reinstalling MySQL with the "use UTF-8" option, and then reimporting all of the data.) I don't have anything in my connection string which mentions Unicode or any charset at all, and I don't have any SQL code which mentions charsets either.

And I do have place names from Slovakia and Iceland in my tables, so I have pretty good test data. Haven't been to Hungary yet but I would like to get there one day.


The point here is, that setting up java client side for transferring into mysql database without the user have to configure anything. So once the user gives the sql user/pass everything else going automaticly. Its needed because on default, java's default charset isnt latin2, so isnt enough to setting up mysql database to latin2 utf8 if you put data through a java program.
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 905
    
    5
Gabor Beke wrote:
The point here is, that setting up java client side for transferring into mysql database without the user have to configure anything. So once the user gives the sql user/pass everything else going automaticly. Its needed because on default, java's default charset isnt latin2, so isnt enough to setting up mysql database to latin2 utf8 if you put data through a java program.



There is a default (platform) encoding, but that applies to the byte stream to (or from) character stream encoding. The JDBC API works in the term of strings, and JDBC takes care of the encoding itself. According to my experience (admittedly with Oracle thin driver) it was neither possible nor necessary to fiddle around with the JDBC encoding.
Gabor Beke
Greenhorn

Joined: Jul 11, 2012
Posts: 16
Ivan Jozsef Balazs wrote:
Gabor Beke wrote:
The point here is, that setting up java client side for transferring into mysql database without the user have to configure anything. So once the user gives the sql user/pass everything else going automaticly. Its needed because on default, java's default charset isnt latin2, so isnt enough to setting up mysql database to latin2 utf8 if you put data through a java program.



There is a default (platform) encoding, but that applies to the byte stream to (or from) character stream encoding. The JDBC API works in the term of strings, and JDBC takes care of the encoding itself. According to my experience (admittedly with Oracle thin driver) it was neither possible nor necessary to fiddle around with the JDBC encoding.


I can say only that, until I didnt do this I got ? marks in my database fields, and if I add this its working, simple solution for me, there's nothing overexplaining about this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting up Character set for mysql table and java