從我的應用程序插入一些中文字符時,它們會以'???'的形式寫入數據庫。不用說,它可以在內置的命令行mysql客戶端中正常工作。MySQL - 問號
連接字符串:
--user-DB-URI = JDBC:MySQL的://本地主機/ tigasedb用戶= tigase_user &密碼= tigase_passwd &了useUnicode =真&的characterEncoding = UTF8 & noAccessToProcedureBodies =真
代碼:
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());
}
這是什麼讓我無法迴避?
編輯:
創建表... ENGINE = InnoDB的默認字符集UTF8整理 utf8_unicode_ci ROW_FORMAT = DYNAMIC;
插入字符:在健身房
驗證是通過內置的命令行mysql客戶端來完成。
編輯: http://docs.oracle.com/cd/E17952_01/refman-5.0-en/connector-j-reference-charsets.html沒有幫助
檢查系統屬性 「的file.encoding」 的價值。如果這不是 「UTF-8」,那麼無論何時將字節解碼爲字符,都需要明確指定「UTF-8」作爲字符 編碼。例如,當您調用帶有byte []的字符串構造函數的 時,或者使用InputStreamReader時使用 。
Problems reading/writing UTF-8 data in MySQL from Java using JDBC connector 5.1 - 沒有幫助
聲明的字符串變量在存儲過程中爲_loc VARCHAR(128) CHARSET utf8
- 沒有幫助
什麼是您的數據庫的字符集和整理? – f1sh
你插入了哪些字符?你如何驗證數據庫存儲的內容?你使用哪種字符集作爲列? – Joni
問題已編輯! – kellogs