Java-Mybatis连接MySQL出错

?useUnicode=true&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/joeaaa/dao/IUserDao.xml
### The error may involve com.joeaaa.dao.IUserDao.findAll
### 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.

解决:

在SqlMapConfig.xml中,对数据库url指定编码字符utf-8

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!--配置环境-->
    <environments default="mysql">
        <environment id="mysql">
            <transactionManager type="JDBC"></transactionManager>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/demo01?useUnicode=true&characterEncoding=utf8"/>
                <property name="username" value="xxx"/>
                <property name="password" value="xxx"/>
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <mapper resource="com/joeaaa/dao/IUserDao.xml"/>
    </mappers>
</configuration>