MySQL Forums
Forum List  »  Connector/JDBC and Java

Re: Unable to retrieve unicode data
Posted by: Mark Matthews
Date: April 26, 2012 01:37PM

Leonard Fernandes Wrote:
> I have isolated this as probably being a JDBC
> issue.

Hi Leonard,

I think you're doing things in a not-supported way, have you read


> After I removed
> keyword = new
> String(keyword.getBytes("ISO-8859-1"), "UTF-8");
> and used the keyword directly, I got some results.
> But it is not consistent and I sometimes get and
> sometimes don't
> Can you help me?
> The code is below:
> /*try {keyword = new
> String(keyword.getBytes("ISO-8859-1"),
> "UTF-8");

Why? Strings are sequences of characters in Java. Don't confuse yourself, or your software by converting them back and forth to byte[]s in encodings needlessly.

> } catch (UnsupportedEncodingException
> usee){keyword = "";}*/
> keyword = Utilities.replaceQuotes(keyword);
> String sequel = "SELECT book_name, book_isbn FROM
> book_resource_view WHERE MATCH(book_name,
> book_isbn, bookauthor) AGAINST ('"+keyword+"') ";

Use a prepared statement, then setString() on it instead of building up this query directly. You're opening yourself up for a SQL injection attack when you do this by hand.

> Connection objConn = null;
> Statement state = null;
> ResultSet results = null;
> ConnectionPool connectionPool = null;
> try {
> connectionPool = new ConnectionPool(10, 50,
> true);
> state = objConn.createStatement();
> String query = "set names utf8";

You're warned not to do this in the manual

now you're finding out why :)

Either set your mysql server to use UTF-8 as the default character set (by setting character_set_server=utf8 in my.cnf), or tell the driver to force using UTF-8 as the client character set with "characterEncoding=UTF-8" as a URL parameter.


Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools

Options: ReplyQuote

Written By
Re: Unable to retrieve unicode data
April 26, 2012 01:37PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.