Hi!

I have a Java application that works with MySQL DB. Until today I used latin alphabet, but now I would like to extend my application to working with cyrillic alphabet. As far as I know, it is possible to use UTF-8. But I don't know the way, in which I should update my code and DB. Could please someone describe me the steps to be performed in order to implement the task? So, it is very important that the application could support BOTH latin and cyrillic alphabets, and be able to switch between the alphabets.

P.S. I found one thread related to this topic. However, this thread discusses only Java web-applications.

Thanks!

I tried ALTER DATABASE db_name CHARACTER SET utf8 COLLATE utf8_general_ci , but it did not help... Some ideas? Please help!!

I tried the following code: db = (Connection) DriverManager.getConnection("jdbc:mysql://" + url + "/" + databasename + "?useUnicode=true&characterEncoding=UTF8",login, pass); . But if I tried to insert a new entry in my DB, and this entry contains cyrillic characters, then I received the error (see below).

The message Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' sounds a bit strange...,because I updated my.ini file and also altered the database (see my previous post). Why "latin1_swedish_ci,IMPLICIT"??? Any ideas? Thanks.

java.sql.SQLException: Incorrect string value: '\xD0\x9F\xD0\xB0\xD0\xBF...' for column 'of_title' at row 1
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2562)
        at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1664)
        at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1583)
        at SystClasses.QueryTableModel.setQueryDontChangeTable(QueryTableModel.java:124)
        at SystClasses.Folder.addOrgFolder(Folder.java:335)
        at SystClasses.Folder.access$700(Folder.java:40)
        at SystClasses.Folder$2.actionPerformed(Folder.java:120)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
        at java.awt.Component.processMouseEvent(Component.java:6263)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6028)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2562)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2512)
        at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1476)
        at SystClasses.Folder.returnDataFromSelectQuery(Folder.java:446)
        at SystClasses.TreeEditTest$3.valueChanged(TreeEditTest.java:328)
        at javax.swing.JTree.fireValueChanged(JTree.java:2820)
        at javax.swing.JTree$TreeSelectionRedirector.valueChanged(JTree.java:3191)
        at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:629)
        at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1078)
        at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:287)
        at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:170)
        at javax.swing.JTree.setSelectionPath(JTree.java:1598)
        at SystClasses.Folder.addOrgFolder(Folder.java:347)
        at SystClasses.Folder.access$700(Folder.java:40)
        at SystClasses.Folder$2.actionPerformed(Folder.java:120)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
        at java.awt.Component.processMouseEvent(Component.java:6263)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6028)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Attached you could see settings of my DB.

This probably seems to be more of a MySQL problem rather than a Java one; you might also want to try posting this to the official MySQL forum or Daniweb's MySQL forum.

Some interesting threads which I stumbled upon which make it seem as if this is a problem with older versions of MySQL:

http://www.vbulletin.com/forum/showthread.php?121120-SQL-Error
http://forums.mysql.com/read.php?26,6528,6528
http://bugs.mysql.com/bug.php?id=3611

I found one thread related to this topic. However, this thread discusses only Java web-applications.

That really shouldn't make a difference if it is MySQL which is the problem maker here. There is not a frightful lot you can do on the Java side except ensure that the user input is passed to the database engine as "utf-8" encoded string and set the connection properties to support the same.

Ok, thank you. I posted this thread to Danyweb's MySQL. It seems that I must define UTF8 for each column of all tables:( or even recreate the DB and tables with UTF8, which is very rutine task:(

It seems that I must define UTF8 for each column of all tables or even recreate the DB and tables with UTF8

This doesn't actually surprise me since we are actually talking about changing the charset here.

which is very rutine task

I'm not sure about the routine part. You are a programmer, it won't be too difficult to whip up a script which does all this for you. :-)

I'm using a MySQL console client, where copy/paste is unavailable. Could you please suggest some more efficient way to copy/paste and run SQL scripts?

You can create and edit a SQL file which contains all the initialization statements (CREATE, INSERT etc.) using a text editor like Notepad++ which supports SQL highlighting and execute the same in MySQL console using the information provided on this page. The advantage here is that whenever you need to reproduce your entire database environment on a clean MySQL install, you just execute this script and you are done! :-)

MySQL workbench looks awesome in case you are not interested in writing SQL scripts in a text editor and executing them at the console.

Ok, thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.