在写spring链接数据库时报以下错:
严重: create connection SQLException, url: jdbc:mysql://localhost:3306/bean, errorCode 0, state S1000
java.sql.SQLException: Unknown initial character set index ‘255’ received from server. Initial client character set can be forced via the ‘characterEncoding’ property.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
需要修改代码:
<!-- 数据库连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
destroy-method="close">
<!-- <property name="url" value="jdbc:mysql://localhost:3306/bean?useUnicode=true&characterEncoding=utf-8" />-->
<property name="url" value="jdbc:mysql://localhost:13306/bean" />
<!-- 13306是5.7版本就不会报错,3306是8.0版本会报错,需要指定编码方式-->
<property name="username" value="root" />
<property name="password" value="llde087a" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
</bean>
换一个版本的MySQL,或者在原先的url后加入
?useUnicode=true&characterEncoding=utf-8
版权声明:本文为future_199原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。