ucas
ucas

Reputation: 487

Storing UTF-8 characters in the MySQL data-base

I am trying to initialize the MySQL data-base relation by words written in Polish language using Java programming language.

This is the line of code:

db.executeQuery("create table "+schema+".category_"+globalId.split("-")[1]+"( id int not null unique, cName varchar(40) not null, primary key (id)) default character set =utf8 collate= utf8_bin;"

It works with German or Swedish language, that is the special characters for that language are stored in data-base as it supposed to be (correct symbols). But when you are trying to write Polish language words it shows ????? instead of special characters for that language.

The same things happens when you are trying to write Chinese letter (you see ??????). I updated character set to bgk or big5, but that did not change anything.

What is the problem? Cheers

Upvotes: 0

Views: 854

Answers (1)

Yoni
Yoni

Reputation: 10321

You need to setup the character set (and maybe collation too) of your database. See here for the documentation. This link is for mysql 5.0, but I think it is very similar in other versions too.

For example:

ALTER DATABASE db_name
[[DEFAULT] CHARACTER SET charset_name]
[[DEFAULT] COLLATE collation_name]

These values that you setup for the database are then used as default for each create table statement. You can also override these values for individual tables.

Update: Here is a better link. It lists the supported character sets in mysql 5.5. I recommend that you use utf8 character set.

Upvotes: 2

Related Questions