一、no data sources are configured to run this sql and provide advanced code assistance警告处理

1.异常错误

  • SpringBoot项目中.xml或者.sql文件调用时报错
No data sources are configured to run this SQL and provide advanced code assistance.

在这里插入图片描述

2.原因

  • 没有配置任何数据源来运行此sql并提供高级代码帮助
  • 意思就是你的项目并未连接到数据库,我们需要做的是连接SQL
  • 需要手动配置数据库客户端工具来连接SQL,并且执行命令创建数据表结构

3.解决方法

1.连接Database

在IDEA左下角的小框中,选择Database

在这里插入图片描述

在右上角弹出的菜单中,点击+号,添加Data Source中的MySQL

在这里插入图片描述
2.配置Mysql

填写你需要连接数据库的相关信息,Host本机就为localhost Port默认为3306,确定URL中的库连接

在这里插入图片描述

点击Test Connection,显示如下信息,则表示数据库链接成功

在这里插入图片描述

二、Loading class `com.mysql.jdbc.Driver’. This is deprecated警告处理

1.异常错误

  • 数据源配置的驱动出错,启动后如果出现以下错误
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.

在这里插入图片描述

2.原因

  • MySQL5用的驱动url是com.mysql.jdbc.Driver
  • MySQL6以后用的是com.mysql.cj.jdbc.Driver。
  • 版本不匹配便会报驱动类已过时的错误。

3.解决方法

当配置好数据库后,还需要在src下找到application.properties数据库配置

  • 本机MySQL版本5.7,driver-Class-name选择com.mysql.jdbc.Driver
  • MySQL时8.0以上,选择com.mysql.cj.jdbc.Driver

在这里插入图片描述

三、Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually警告处理

1.异常错误

  • 时区设置错误
Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually

2.原因

  • 时区不一致,MySQL驱动jar中的默认时区是UTC,代表的是全球标准时间
  • 我们使用的时间北京时区是东八区,领先UTC八个小时
  • com.mysql.cj.jdbc.Driver是mysql-connector-java 6中的特性
  • 相比mysql-connector-java 5 多了一个时区serverTimezone

3.解决方法

在这里插入图片描述
Advanced中将serverTimezone设置成Hongkong或者UTC,然后点击 APPLY

在这里插入图片描述

再次尝试 Test Connection 成功连接

在这里插入图片描述

四、Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded警告处理

1.异常错误

  • url配置数据源出错,未能确定合适的驱动程序类
Failed to configure a DataSource: 'url' attribute is not specified and no embedded

2.原因

  • pom.xml文件中添加了mybatis依赖
  • application.properties中没有配置连接数据库的url、用户名user 、和密码 password
  • pom.xml文件中添加了有关数据库的依赖时,需要在属性文件中配置连接该库的路径,用户名和密码

3.解决方法

  • application.properties填写相关配置信息,注意url连接数据库路径 url=jdbc:mysql://localhost:3306/test 这里的test指直接连接的数据库
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=xxxxxxxx
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
server.port=8004
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

mybatis.mapper-locations=classpath:mapper/*.xml

在这里插入图片描述

五、Cause: java.sql.SQLSyntaxErrorException: Table ‘mybatis.users‘ doesn‘t exist警告处理

1.异常错误

Cause: java.sql.SQLSyntaxErrorException: Table ‘mybatis.users‘ doesn‘t exist

2.原因

  • 出现此问题原因跟四一样,url配置不正确,导致找不到数据库中相关表
  • 或者是mapper.xml文件中查询条件出错导致

在这里插入图片描述

在这里插入图片描述

3.解决方法

  • 如果是url配置不正确,则参考四的解决方法
  • 如果是查询条件出错,查看语法错误并修改

异常索引

  • no data sources are configured to run this sql and provide advanced code assistance警告处理
  • Loading class `com.mysql.jdbc.Driver’. This is deprecated警告处理
  • Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually警告处理
  • Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded警告处理
  • Cause: java.sql.SQLSyntaxErrorException: Table ‘mybatis.users‘ doesn‘t exist警告处理
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐