- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
'"-6ren"> '"-我有下表 name为 LATIN1,其余为 UTF8。 CREATE TABLE `test_names` ( `name` varchar(500) CHARACTER SET latin1 C-6ren">
我有下表 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)
最佳答案
在我这边,我可以给你一些建议
SET NAMES='utf8'
将 &characterEncoding=UTF-8
添加到您的 JDBC 连接字符串中。希望你已经做到了。
使用convert() 进行插入或更新
,使用cast() 进行选择
查询。更多详情 http://dev.mysql.com/doc/refman/5.7/en/charset-convert.html
关于java - ResultSet.updateRow() 产生 "Illegal mix of collations (latin1_bin,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ' <= >'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35729991/
我是一名优秀的程序员,十分优秀!