I want to do a query by title like this:
String title = "transfusión";
String sql = "SELECT id FROM graph WHERE title=?";
PreparedStatement st = conn.prepareStatement(sql);
st.setString(1, title);
st.executeQuery();
The problem is that title column charset is latin1 and my java file encoding is utf8. When the title variable contains special caracters like accents, the query never finds a result.
I'm using a MySQL database an the connection url is:
jdbc:mysql://mysite:3306/mydatabase?autoReconnect=true&characterEncoding=latin1&useOldAliasMetadataBehavior=true
I tried multiple alternatives using useUnicode=true/false or characterEncoding=latin1/utf8/auto but I never get any result.
Also I tried to convert title and sql to ISO-8859-1 before prepare statement like this:
title = new String(title.getBytes("UTF-8"), "ISO-8859-1");
sql = new String(sql.getBytes("UTF-8"), "ISO-8859-1");
I can't change the database's charset because I'm not the administrator.
How can I solve that?
PD: Sorry for my English.
0as the argument index. Are you catching and suppressing an exception somewhere? - Andy TurneruseUnicode=true&characterEncoding=UTF-8from my UTF-8 encoded .java file and it found the row in thelatin1column without complaint. I suspect that there is something else wrong with your code, especially sincesetString(0, ...)will FAIL with "Parameter index out of range (0 < 1 )". - Gord Thompson