问题遇到的现象和发生背景
最近再跟着韩顺平teacher的java课程学到满汉楼部分,在使用druid连接池连接数据库时报错,我参考了相关的教程将mysql驱动版本改为了8.0.11,后续报出如下错误:
javaagent:D:\OTHERS\software\IDEA\IntelliJ IDEA 2020.2.4\lib\idea_rt.jar=59639:D:\OTHERS\software\IDEA\IntelliJ IDEA 2020.2.4\bin" -Dfile.encoding=UTF-8 -classpath D:\OTHERS\Projects\IDEA_workspace\mhl\out\production\mhl;D:\OTHERS\Projects\IDEA_workspace\mhl\libs\commons-dbutils-1.3.jar;D:\OTHERS\Projects\IDEA_workspace\mhl\libs\druid-1.1.10.jar;D:\OTHERS\Projects\IDEA_workspace\mhl\libs\mysql-connector-java-8.0.11.jar com.hspedu.mhl.utils.Test
8月 15, 2022 8:37:29 上午 com.alibaba.druid.pool.DruidDataSource error
严重: init datasource error, url: jdbc:mysql://localhost:3306/mhl?useSSL=false&serverTimezone=GMT%2B8
java.sql.SQLSyntaxErrorException: Unknown error 1049
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:118)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1558)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1623)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:861)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1229)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1225)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:90)
at com.hspedu.mhl.utils.JDBCUtilsByDruid.getConnection(JDBCUtilsByDruid.java:36)
at com.hspedu.mhl.utils.Test.main(Test.java:14)
8月 15, 2022 8:37:29 上午 com.alibaba.druid.pool.DruidDataSource error
严重: {dataSource-1} init error
java.sql.SQLSyntaxErrorException: Unknown error 1049
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:118)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1558)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1623)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:861)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1229)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1225)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:90)
at com.hspedu.mhl.utils.JDBCUtilsByDruid.getConnection(JDBCUtilsByDruid.java:36)
at com.hspedu.mhl.utils.Test.main(Test.java:14)
8月 15, 2022 8:37:29 上午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} inited
Exception in thread "main" java.sql.SQLSyntaxErrorException: Unknown error 1049
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:118)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1558)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1623)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:861)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1229)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1225)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:90)
at com.hspedu.mhl.utils.JDBCUtilsByDruid.getConnection(JDBCUtilsByDruid.java:36)
at com.hspedu.mhl.utils.Test.main(Test.java:14)
Process finished with exit code 1
研究好久不知道是什么问题,还请大家指点指点
以下是相关配置文件与代码
druid.propertites
#key=value
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/mhl?useSSL=false&serverTimezone=GMT%2B8
username=root
password=hsp
#initial connection Size
initialSize=10
#min idle connecton size
minIdle=5
#max active connection size
maxActive=50
#max wait time (5000 mil seconds)
maxWait=5000