java WEB 操作Mysql Hibernate

org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:254)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1001)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:339)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.baidu.test.test.main(test.java:38)
Caused by: java.sql.BatchUpdateException: Incorrect string value: '\xE5\x8C\x96\xE5\xAD\xA6' for column 'project' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1269)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:955)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:247)
... 8 more
-----------------------------------------------------------------------------
代码出错

原因是因为我在hibernate.cfg.xml中  加入了
-----------------------------------------------------------------------------
<property name="connection.url">
         jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8
    </property>
    -----------------------------------------------------------------------------
为什么要加入这段呢  因为我之前插入中文显示问号

s.setProject("物");
        s.setScore(80);
        ss.setProject("化学");
        可是加入之后就出bug了

        就算我把"物"换成 URLEncoder.encode("物", "utf-8");也不行
        ------------------------------------------------------------------------
        mysql status和show variables like '%char%'如下所示:
        mysql  Ver 14.14 Distrib 5.6.24, for Win32 (x86)

Connection id: 2
Current database: test
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.6.24 MySQL Community Server (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: latin1
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306

Uptime: 4 min 38 sec

+--------------------------+------------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | D:\software\mysql-5.6.24-win32\share\charsets\ |
+--------------------------+------------------------------------------------+
纠结一晚上了 求助
图片说明

1个回答

你数据库的编码是utf8吗

s664298595
s664298595 是的 所有编码都是UTF-8 如果没使用set names utf8的话 | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | 是GBK 但是我也试过用GBK 还是问号。
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问