Tag Archives: Mybatis-config Error

[Solved] Mybatis-config Error: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: failed to parse the connection string near ‘;useUnicode=true&

 

situation:

If you want to transfer the db.properties data in the resource to mybatis config, there is an error running userdaotest

db.properties:

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT
username=root
password=123456

mybatis-config.xml

<?xml version="1.0" encoding="utf8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
    <properties resource="db.properties" />

    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="${driver}"/>
                <property name="url" value="${url}"/>
                <property name="username" value="${username}"/>
                <property name="password" value="${password}"/>
            </dataSource>
        </environment>
    </environments>


    <mappers>
        <mapper resource="com/kuang/dao/UserMapper.xml"/>
    </mappers>
</configuration>

Errors are:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=GMT'.
### The error may exist in com/kuang/dao/UserMapper.xml
### The error may involve com.kuang.dao.UserMapper.getUserLike
### The error occurred while executing a query
### Cause: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=GMT'.

According to the error information, locate the db.properties file and Baidu to the following link:

Mybatis configuration error cannot load connection class because of underlying exception: com.Mysql.CJ.Exceptions

Transfer the content of the properties tag of the xml file in mybatis to another external configuration file jdbcCondig.properties to report an error

I realized that the interpretation of && in the url part of the .properties file and the .xml database connection should be different. In the .xml file, && should be written as &
and in .properties it should be &&, so I put .xml The & in the url of the file is changed to && and it runs successfully.

Amend to read:

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis?useSSL=true&&useUnicode=true&&characterEncoding=UTF-8&&serverTimezone=GMT
username=root
password=123456

Solved.