How to insert Indian font characters in MySql database using JAVA

Hello friends,

This blog is regarding my latest finding while working on my website Assamesebooks.com
As the name suggests, the website is all about Assamese literature and hence the books names had to be displayed in assamese as well.

I have created a dataload utility to load the product data from excel file into the mySql database.
The data in the excel file is in assamese font. Now the problem was that after the dataload, the assamese font  were not getting saved properly in the DB and were visible as ???? (question marks)

First I thought it might be due to the CHARSET or CHARACTER ENCODING that I had selected for my database schema and the table. But there were set to utf8_general_ci

This kept me puzzled for quite some time. While googling I came across the real solution which was related to how I was creating my JDBC connection URL.
In order to have the UNICODE characters saved properly to the mysql database we need to specify to use unicode and character encoding as UTF-8 while making the JDBC connection URL for databse.
This can be done by simply adding following parameters to the connection URL i.e. useUnicode=true&characterEncoding=UTF-8

So, your JDBC connection URL my look like,

String url = "jdbc:mysql://localhost/TestDB?useUnicode=true&characterEncoding=UTF-8";

Hope this information comes handy to you people as well.

Cheers! and happy coding :-)

PS: The google page where I found this helpful tip is :
http://uwudamith.wordpress.com/2011/09/02/how-to-insert-unicode-values-to-mysql-using-java/

0 comments:

Post a Comment