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(
“user”, “pass”, “com.mysql.jdbc.Driver”)
// We assume db table similar to:
CREATE TABLE IF NOT EXISTS `your_databset` (
`id` bigint(32) NOT NULL AUTO_INCREMENT,
`text` varchar(500) NOT NULL,
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 setup “characterEncoding=UTF-8“ letters become to be crapped. My issue was caused by Czech charset.