解决问题:Cause: java.sql.SQLException: Unknown initial character set index ‘255‘ received from server.

在执行MyBatis查询时遇到一个PersistenceException,具体原因是数据库连接字符集未知(255)。通过在jdbc.url中添加characterEncoding=utf8参数,解决了这个问题。

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.
### The error may exist in com/itheima/dao/AccountDao.java (best guess)
### The error may involve com.itheima.dao.AccountDao.findById
### The error occurred while executing a query
### Cause: java.sql.SQLException: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87)
    at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
    at com.sun.proxy.$Proxy9.findById(Unknown Source)
    at App_mybatis.main(App_mybatis.java:28)

 解决://jdbc.url = "jdbc:mysql://localhost:3306/spring_db" 如果使用这句就会报错。
//Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.
jdbc.url = "jdbc:mysql://localhost:3306/spring_db?&characterEncoding=utf8";//改成这句,就可以了

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值