'"-6ren"> '"-我有下表 name为 LATIN1,其余为 UTF8。 CREATE TABLE `test_names` ( `name` varchar(500) CHARACTER SET latin1 C-6ren">
gpt4 book ai didi

java - ResultSet.updateRow() 产生 "Illegal mix of collations (latin1_bin,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ' <= >'"

转载 作者:可可西里 更新时间:2023-11-01 08:39:59 26 4
gpt4 key购买 nike

我有下表 name为 LATIN1,其余为 UTF8。

CREATE TABLE `test_names` (
`name` varchar(500) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
`other_stuff_1` int DEFAULT NULL,
`other_stuff_2` varchar(45) DEFAULT NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

我在 Java 中遇到以下问题:

SELECT ... FOR UPDATE .然后我调用updateInt(2, 1)updateRow()在它的 ResultSet 上得到 Illegal mix of collations (latin1_bin,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '<=>' .

如何在不更改表/连接的字符集的情况下完成这项工作?

非常感谢。

---更新---

我使用 SELECT name, other_stuff_1 FROM test_names LIMIT 1 FOR UPDATE;连接字符串是 DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + db + "?allowMultiQueries=true", user, password); .

确切的堆栈跟踪是:

java.sql.SQLException: Illegal mix of collations (latin1_bin,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '<=>'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2834)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2441)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2366)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2350)
at com.mysql.jdbc.UpdatableResultSet.updateRow(UpdatableResultSet.java:2405)

最佳答案

在我这边,我可以给你一些建议

  1. 首先更新您的 Connector/J 最新版本。
  2. 运行此查询
SET NAMES='utf8'
  1. &characterEncoding=UTF-8 添加到您的 JDBC 连接字符串中。希望你已经做到了。

  2. 使用convert() 进行插入或更新,使用cast() 进行选择 查询。更多详情 http://dev.mysql.com/doc/refman/5.7/en/charset-convert.html

  3. 非法混用相关问题,可以跟进Troubleshooting "Illegal mix of collations" error in mysql

关于java - ResultSet.updateRow() 产生 "Illegal mix of collations (latin1_bin,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ' <= >'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35729991/

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