gpt4 book ai didi

java - MySQL——问号

转载 作者:行者123 更新时间:2023-11-30 01:26:11 30 4
gpt4 key购买 nike

当从我的应用程序插入一些中文字符时,它们会被写入数据库为“???”。不用说,在内置的命令行 mysql 客户端中一切都可以正常工作。

连接字符串:

--user-db-uri = jdbc:mysql://localhost/tigasedb?user=tigase_user&password=tigase_passwd&useUnicode=true&characterEncoding=utf8&noAccessToProcedureBodies=true

代码:

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());
}

到底是什么让我无法理解?

编辑:

create table ... ENGINE=InnoDB default character set utf8 collate utf8_unicode_ci ROW_FORMAT=DYNAMIC;

插入的字符:在健身房

验证是通过内置的命令行 mysql 客户端完成的。

编辑: http://docs.oracle.com/cd/E17952_01/refman-5.0-en/connector-j-reference-charsets.html没有帮助

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 - 没有帮助

在存储过程中将字符串变量声明为 _loc VARCHAR(128) CHARSET utf8 - 没有帮助

最佳答案

您的数据库表列应使用正确的字符集和排序规则创建。您可以在创建或更改表时定义它:

col_name {CHAR | VARCHAR | TEXT} (col_length)
[CHARACTER SET charset_name]
[COLLATE collation_name]

这里是 mysql 链接,可帮助您了解更多信息:

http://dev.mysql.com/doc/refman/5.0/en/charset-column.html

关于java - MySQL——问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17968626/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com