Home > brief news, JAVA > Groovy: MySQL connection with UTF-8 encoding/charset

Groovy: MySQL connection with UTF-8 encoding/charset

The UTF-8 is an important encoding because of the following reasons. It’s ASCII compatible, easily supported, compact and efficient for most scripts, easily processed, unlike other multibyte encodings.

When I worked on data conversion procedure used for Machines in industry I found out that UTF-8 is one of the most important thing.  It’s very clever to keep your attention here because it could damage many things and Machines don’t do so.

I suppose you have well setup your IDE and Database to ‘UTF-8′. When you are importing data to Database you have seen crapped letters like ‘âøñè?’. Maybe you spend hours by googling why?  Try out following in Groovy, of course:

Sql sql = Sql.newInstance(
jdbc:mysql://localhost:3306/your_database?useUnicode=true&characterEncoding=UTF-8“,
“user”, “pass”, “com.mysql.jdbc.Driver”)

// We assume db table similar to:
sql.execute(“””
CREATE TABLE IF NOT EXISTS `your_databset` (
`id` bigint(32) NOT NULL AUTO_INCREMENT,
`text` varchar(500) NOT NULL,

) CHARSET=utf8;
“””)

The most important is the line starts with “jdbc:mysql://localhost …“. Although utf-8 charset behaves very well inside your IDE log output if you don’t have setupcharacterEncoding=UTF-8 letters become to be crapped. My issue was caused by Czech charset.

About these ads
Categories: brief news, JAVA
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: