Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8153795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:08:11+00:00 2026-06-06T16:08:11+00:00

I looked in the mysql reference, and here, in stackoverflow, and looks like a

  • 0

I looked in the mysql reference, and here, in stackoverflow, and looks like a lot of people are having difficulties with character encoding, but I couldn’t find a clear answer to this problem:

A java program is using a mysql database, and when there are special characters in the query like ű,ő (but á,é,í,ó,ú works), it throws an SQLException:

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn = DriverManager.getConnection(
            "jdbc:odbc:<database>", "<user>", "<pass>"
            );

    PreparedStatement stmt = conn.prepareStatement(
            " select username, priority " +
            " from users " +
            " where username like ?");
            //" where username like ? collate latin2_general_ci");
    stmt.setString(1, "Ernő");
    ResultSet rs = stmt.executeQuery();
    while(rs.next()) {
        System.out.println(rs.getString("username") + "  " + rs.getInt("priority"));
    }

Exception:

Exception in thread "main" java.sql.SQLException:
[MySQL][ODBC 5.1 Driver][mysqld-5.1.63-0ubuntu0.10.04.1]
Illegal mix of collations (latin2_hungarian_ci,IMPLICIT)
and (latin1_swedish_ci,COERCIBLE) for operation 'like'

The table structure is:

CREATE TABLE `users` (
`username` varchar(45) COLLATE latin2_hungarian_ci NOT NULL,
`password` varchar(45) COLLATE latin2_hungarian_ci NOT NULL,
`priority` tinyint(4) NOT NULL,
`idCimlistaFK` int(10) unsigned DEFAULT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`username`),
KEY `fk_users_tbl_Cimlista1` (`idCimlistaFK`),
CONSTRAINT `fk_users_tbl_Cimlista1` FOREIGN KEY (`idCimlistaFK`)
REFERENCES `tbl_cimlista` (`id_Cimlista`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_hungarian_ci 

When I tried to force a collation like in the commented line:

" where username like ? collate latin2_general_ci");

It also throws an exception:

COLLATION 'latin2_general_ci' is not valid for CHARACTER SET 'latin1'

Does anyone know, how to solve this (possibly within java)? (I would prefer not to change the database, because it’s a legacy system.)

UPDATE:

I used the following url, as suggested by Rahul Agrawal:

"jdbc:mysql://localhost:3306/database?characterEncoding=latin2"

It did work, however, I noticed a sideeffect.
When I updated and inserted data with the testserver, wich runs mysql on a win XP machine, it went fine. But when I updated and inserted the data to the production server running Ubuntu, I did get rows, wich had ?-signs instead ő,ű-letters. I resolved this with a workaround since, but it would be nice to see and understand, what went wrong, what are the issues here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:08:13+00:00Added an answer on June 6, 2026 at 4:08 pm

    You need to use UTF-8 charset

    In Connection URL try this

    jdbc:mysql://localhost:3306/testdb?characterEncoding=utf8
    

    Database CHARSET=utf8

    Database Collation = utf8_general_ci

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

MySQL noob here; looked around first but couldn't find the answer to this question.
Having looked at some of the other mysql availability query questions on here has
I've looked on Google but couldn't find it. Can we order in MySQL using
I looked for a specific answer to this question, but couldn't find it --
How do I merge two tables in MySQL? I've looked at several other posts
I looked through the other posts and bug reports and couldn't figure out what's
I looked around and found that there is an onerror function for flexigrid but
I looked all around SOF but no luck to find me answer. It is
I'm playing with timezones in MySQL. I need to assign people to timezones, and
I looked at the MySql Connection Options and it doesnt seem to be there.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.