Error: SpringMVC+Spring+MyBatis

19-Feb-2021 11: 08:54.808Serious [Druid - ConnectionPool - Create -1512829159] com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl.error create connection SQLException, url: jdbc:mysql://localhost:3306/springdb, 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)
		at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1734)
		at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3539)
		at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2151)
		at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:776)
		at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
		at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
		at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
		at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
		at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
		at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
		at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
		at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284)
		at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1570)
		at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1636)
		at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2505)
Copy the code

Mysql driver 8.0.22: mysql driver 8.0.22: mysql driver 8.0.22: mysql driver 8.0.22: mysql driver 8.0.22: mysql driver 8.0.22: mysql driver 8.0.22: mysql driver 8.0.22: mysql driver 8.0.22

   <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.22</version>
        </dependency>
Copy the code

Baidu also found that driverClassName may report this error, but this is not the reason

DriverClassName: com.mysql.jdbc.driver # mysql-connector- Java 5.x driverClassName: com.mysql.jdbc.driver # mysql-connector- Java 5.x Driver # mysql-connector- Java 6.x and laterCopy the code

Student: One question here?

  1. DriverClassName can access the database even if no application is configured. How does this work?

2. CharacterEncoding =UTF-8

    <! Declare data source, connect to database -->
    <context:property-placeholder location="classpath:conf/jdbc.properties"/>
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
<! -- <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>-->
<! -- <property name="url" value="${jdbc.url}? characterEncoding=UTF-8"/>-->
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>

Copy the code

Question 1: driverClassName can access the database even if no application is configured. How does this work? There may be the following situation with the guidance of the big man (not verified, recorded first, there is time to verify later)

  1. This is already configured in the mysql driver JAR

  1. In com. Alibaba. Druid. Pool. DruidDataSource configuration