阅读更多
今天在linux上部署应用程序后出现以下异常:
Caused by: java.sql.SQLException: Illegal mix of collations (gb2312_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2994)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:137)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1676)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
... 31 more
在网上找了半天没找到解决办法,后来把改表的创建脚本调出来一看
CREATE TABLE `applogs` (
`id` int(10) unsigned NOT NULL auto_increment,
`loginfo` varchar(32) NOT NULL,
`dn` varchar(32) NOT NULL,
`type` int(10) unsigned NOT NULL,
`logtime` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
然后把DEFAULT CHARSET=latin1改成DEFAULT CHARSET=gb2312重新创建该表就ok了。
估计在linux上装的是mysql 4的版本,在我自己机子上装的是mysql 5,新的版本不存在这个问题