在线商城系统 报错 ERROR [com.alibaba.druid.pool.DruidDataSource] - create connection error

系统使用Maven管理jar包,数据库为mysql

问题:系统换了台电脑运行报错,连接不上数据库,报下面的错误:

2019-11-27 22:43:18,418 ERROR [com.alibaba.druid.pool.DruidDataSource] - create connection error
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    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:408)
    at com.mysql.jdbc.Util.getInstance(Util.java:383)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1023)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:997)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:983)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:928)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2576)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2309)
    at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:834)
    at com.mysql.jdbc.JDBC4Connection.(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:408)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:419)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
    at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1375)
    at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1431)
    at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1844)
Caused by: java.lang.NullPointerException
    at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:3299)
    at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1967)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1893)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1287)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2494)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2527)
    ... 13 more

 

问题原因:新电脑上的mysql的版本为8.0.18

在线商城系统 报错 ERROR [com.alibaba.druid.pool.DruidDataSource] - create connection error_第1张图片

而系统的pom.xml文件中管理的mysql版本为5.1.32

在线商城系统 报错 ERROR [com.alibaba.druid.pool.DruidDataSource] - create connection error_第2张图片

解决方法:

1:将mysql的jar包版本改为和系统一致

2.将连接数据库时的驱动由jdbc.driver=com.mysql.jdbc.Driver 换成jdbc.driver=com.mysql.cj.jdbc.Driver

3:在url之后加上时区

jdbc.url=jdbc:mysql://localhost:3306/e3-mall?characterEncoding=utf-8&serverTimezone=UTC

4:依赖项目重新maven install

你可能感兴趣的:(数据库)