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.