when inserting from my app some chinese characters they get written into DB as '???'. Needless to say it all works fine from within the built in command line mysql client.
Connection string:
--user-db-uri = jdbc:mysql://localhost/tigasedb?user=tigase_user&password=tigase_passwd&useUnicode=true&characterEncoding=utf8&noAccessToProcedureBodies=true
Code:
try {
conn_valid_st.setQueryTimeout(query_timeout);
st = conn.prepareStatement("SET character_set_client = utf8");
st.execute();
st.close();
st = conn.prepareStatement("SET character_set_connection = utf8");
st.execute();
st.close();
st = conn.prepareStatement("SET character_set_results = utf8");
st.execute();
st.close();
st = conn.prepareStatement("SET collation_connection = utf8_general_ci");
st.execute();
st.close();
st = conn.prepareStatement("SET NAMES utf8");
st.execute();
st.close();
st = conn.prepareStatement("SET CHARACTER SET utf8");
st.execute();
st.close();
} catch (SQLException ex) {
// Ignore for now, it seems that PostgreSQL does not support this method
// call yet
if (null != st)
st.close();
log.log(Level.WARNING, "DB server said: {0}", ex.toString());
}
What is it that eludes me ?
EDIT:
create table ... ENGINE=InnoDB default character set utf8 collate utf8_unicode_ci ROW_FORMAT=DYNAMIC;
inserted characters: 在健身房
Verification is done by the built in command line mysql client.
EDIT: http://docs.oracle.com/cd/E17952_01/refman-5.0-en/connector-j-reference-charsets.html did not help
Check the value of the system property "file.encoding". If that is not "UTF-8", then you need to explicitly specify "UTF-8" as the character encoding whenever you decode bytes to characters. For example, when you call a String constructor with a byte[], or use an InputStreamReader.
Problems reading/writing UTF-8 data in MySQL from Java using JDBC connector 5.1 - did not help
Declared string variables in stored procedures as _loc VARCHAR(128) CHARSET utf8
- did not help