数据库资源配置异常记录
创建spring boot项目时,访问静态资源和数据库,主要配置数据源信息,这里使用application.yml格式(也可以使用application.properties)的形式,看个人喜欢,application.yml配置如下:
spring:
datasource:
#注意这里的com.mysql.jdbc.Driver已经被启用换成com.mysql.cj.jdbc.Driver
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/homework?&characterEncoding=UTF-8
username: root
password: admin
运行起来,结果报错:
java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
第一个异常解决方法:
把com.mysql.jdbc.Driver 改为com.mysql.cj.jdbc.Driver 即可(新的mysql数据库驱动类改为了com.,mysql.cj.jdbc.Driver)
第二个异常解决方法:
java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time
提示服务器区值也就是系统时区出现错误,这是后在数据库驱动的url后面加serverTimezone=UTC参数,即可。
运行成功: