SpringBoot 2.1.0更新后连接数据库的恶心Bug(2)

~~~作者在忙碌的生活中找到了唯一的生活乐趣就是在北京挤死人的地铁中停一会评书(单口相声),故作者也想淫诗一首:说书长期劝人方,三条大陆走中央,善恶到头终有报,人间正道是沧桑。不过话说听相声还得听郭德纲。

书归正题,这个bug是我在用springboot2.1的时候直接从官网上下载了一个demo,所以springboot的版本和数据库连接驱动的版本都应该是最新版本的,本来听说朋友们最近mybatisplus我说我也写一个demo看看有没有他们口中说的那么的强大,但是已启动项目直接报了如下的错误了,大概意思看懂了,但是由于作者的英语水平实在是有限,便从网上搜了一下,由于新版的数据库驱动中类com.mysql.jdbc.Driver,改名为com.mysql.cj.jdbc.Driver,所以在写数据库连接驱动是要使用com.mysql.cj.jdbc.Driver了:

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)

at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:455)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)

at java.sql.DriverManager.getConnection(DriverManager.java:664)

at java.sql.DriverManager.getConnection(DriverManager.java:247)

at com.baomidou.mybatisplus.generator.config.DataSourceConfig.getConn(DataSourceConfig.java:171)

at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.handlerDataSource(ConfigBuilder.java:287)

at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.(ConfigBuilder.java:139)

at com.baomidou.mybatisplus.generator.AutoGenerator.execute(AutoGenerator.java:88)

at com.example.demo.CodeGenerator.main(CodeGenerator.java:104)

Exception in thread "main" java.lang.NullPointerException

at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.getTablesInfo(ConfigBuilder.java:469)

at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.handlerStrategy(ConfigBuilder.java:301)

at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.(ConfigBuilder.java:146)

at com.baomidou.mybatisplus.generator.AutoGenerator.execute(AutoGenerator.java:88)

at com.example.demo.CodeGenerator.main(CodeGenerator.java:104)

Disconnected from the target VM, address: '127.0.0.1:54402', transport: 'socket'

ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2

JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [util.c:840]

解决问题:将连接数据库的驱动类由com.mysql.jdbc.Driver更改为com.mysql.cj.jdbc.Driver即可。

你可能感兴趣的:(SpringBoot 2.1.0更新后连接数据库的恶心Bug(2))