Hello friends.. Today i have came up with something new for me.. and i think this will be useful for me.Specially for our Sri Lankan friends who are willing to develop Sinhale Unicode based java programs.Here i used basic two concepts.
- First one is Insert Unicode format values to MySQL database
- Retrieve data and display it using a combo box.
I know if you can insert and retrieve data you can handle anything based on it. So lets starts the works. In this post i will tel you how to create a database in MySQL and create tables and fields to store data in Unicode format.
Another important thing you must know.I normally use my own ways when i am programming. I mean the way i am developing programs may be unique to me.Please consider about this when you are getting something from here.
Create a database in MySQL
- I used phpMyAdmin to create my database and sometimes i used MySQL GUI tools for check my values.
- MySQL GUI tools support to view Unicode values from a database
- See my SQL backup file below and you can restore this backup file using phpMyAdmin.
-- -- Database: `unicode` -- CREATE DATABASE `unicode` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; USE `unicode`; -- -------------------------------------------------------- -- -------------------------------------------------------- -- -- Table structure for table `unicode` -- CREATE TABLE IF NOT EXISTS `unicode` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `job` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=20 ;
Don’t worry at the end of the line you can download my database backup file. See i have created database in utf8_general_ci format and my table also in that format.
Now you have a database that you can store values in Unicode formats. If you cannot understand what i am saying see below screenshot. I got the
You can see some of values display as ??? and u0dc3 and my native language.
- Up to 6 id i inserted values from manually using MySQL GUI tools.
- In id 16 i inserted values from jTextBox and when i am insert it i got only ??? marks in my database.I tried several times using different methods but i couldn’t fix it.( Don’t worry i fixed it in this movement )
OK i am now going to give my Connection class. If you saw my previous posts i used my connection class in same way but now i added something extra to my connection class.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication1; import java.sql.Connection; import java.sql.DriverManager; import javax.swing.JOptionPane; /** * * @author Developer */ public class connection { public Connection creatConnection () throws ClassNotFoundException { Connection conn=null; try { Class.forName("com.mysql.jdbc.Driver").newInstance();//call jdbc driver String url = "jdbc:mysql://localhost/unicode?useUnicode=true&characterEncoding=UTF-8";//getting url conn = DriverManager.getConnection(url,"root","");//create connection } catch (Exception e) { // JOptionPane.showMessageDialog(null,"Error occured!.."+ e.getLocalizedMessage()); JOptionPane.showMessageDialog(null, e.getMessage(), "Ooops",JOptionPane.ERROR_MESSAGE, null);//exeption hanling } return conn;//return connection to all } }
OK. Now see clearly this code. I said i had some ??? values. The way i fixed it, i used this extra code to end of my string ( ?useUnicode=true&characterEncoding=UTF-8″; )
String url = “jdbc:mysql://localhost/unicode?useUnicode=true&characterEncoding=UTF-8”;
OK Now you created the connection class successfully. I will see you in next post How to insert data using java GUI.
Thank you for your sample . I want to convert data into sinhala unicode font and store the mysql database. But couldn’t find that method. I ask many java developers my problem. but couldn’t find correct answer. Again I was thank to you.
Thank you for comment on my blog.. and i do because human knowledge belongs to the world..
holy sh***! This is what i wanted bro. You are a hell of Angel… thanks for the “trailing code”! may be there is where I missed my shoes on crowd.
Thanks a lot bro.
man i works…. great…. thanks for the “trailing code”…. refer me where you find these things…. 😉 keep in touch if you wish… i am a java freak… hope we could share a lot …
Of course knowledge is all about sharing…
Thanks a lot…
Thank you for your comment on my blog.i always try to share my knowledge..
It’s very kind of you,Thank you so much. 🙂
You are welcome…
hi, thanks for your guide on this, but unfortunately I still couldn’t solve my problem. If you’re willing to help me then I will email you the screenshot of my java code and settings in phpmyadmin.
Yes. Send me files and if i know something i will help you my friend..
Thank you very much buddy… 🙂
You are welcome buddy..
Thanks a lot…
thanks ayya
Dear Damith,
I try to insert the tamil unicode chars to the database, again it is showing like full of question marks, do i need any specific font for this?.
Is your connection string contains this extra words at the end? Here i have bolted them. String url = “jdbc:mysql://localhost/unicode?useUnicode=true&characterEncoding=UTF-8“;
dude… I love you for this post… Had been struggling with this issue for like 5 hours..
This is an impeccable tutorial indeed…Thnx ayya…great work
i wanna get sinhala input (sinhala names) to my programme. But i couldn’t. How to get using java ?
Please check this post
ඔබගේ ක්රමය නිවැරදියි. අපත් සමඟ බෙදා හදා ගත්තාට තුති.
thanks a lot
Thanks a lot. Your comment saved us lot of time. However we used “CharSet” parameter in the connection string without changing the server url. i.e “CharSet=utf8;”
Nice to here about it.
it do this. but the message is unsupport character.. could you show us more?
I have published all possible codes here.
thanks…
u was help me…..
Thanks a lot bro. you saved my day…..
so thanks…………..i got a help!
but how to retrieve these values and display on GUI using swing
Did you check this blog post
https://uwudamith.wordpress.com/2011/10/20/how-to-insert-unicode-values-to-mysql-using-java-part-3/
Thank you!! 🙂
How can i show native characters from mysql database using textview in android.??
I am sorry to say that i have not much experience in android.
how to do it in malayalam?
thank you lot
i really thank you…..i was in in trouble a lot for this unicode….thank you so much beyaa
Happy to hear that.. 🙂
Thank you very much..,mata kiyanna komada Search query ekak hadanne sinhala keyword ekakata anuwa search karanna…?
thanks
Thanks…bro…
java textField ekak ක්රීම් lesa sadahan karaama ක්රීම් kiyalane type wenne.mekata hethuwa mokka.meka fix karanna puluwanda.plz help
dear but it not working in desktop app , guide me . i want store sindhi or urdu character in table using java code in desktop app
شسData truncation: Incorrect string value: ‘\xD8\xB4\xD8\xB3’ for column ‘purchaseName’ at row 230
0