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&characterEncoding=UTF-8&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&characterEncoding=UTF-8&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.
Similar Posts:
- For the problem of establishing SSL connection in mysql, set usessl = false to explicitly disable SSL, or set usessl = true
- Failed to obtain JDBC Connection
- [Solved] MySQL Error: com.mysql.cj.jdbc.util.TimeUtil.loadTimeZoneMappings(TimeUtil.java:163)
- Logstash output jdbc Error: java.lang.IllegalAccessError: tried to access class com.mysql.jdbc.EscapeProcessor from class com.mysql.jdbc.ConnectionImpl
- [Solved] Springboot Project Connect MYSQL Error: Establishing SSL connection without server’s identity verification is not recommended.
- [Solved] Spring Error: java.sql.SQLException: Access denied for user ‘${user}’@’localhost’ (using password: YES)
- [Solved] JMeter Use the JDBC linker Error: Unknown initial character set index ‘255’ received from server.initial client character
- [Solved] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.6…
- [Solved] ### Error querying database. Cause: java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or represents more XXXXX
- [Solved] spark Connect hive Error: javax.jdo.JDODataStoreException: Required table missing : “`DBS`” in Catalog “” Schema “”