***ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUrl("jdbc:mysql://localhost:3306/jdbc");
ds.setUsername("root");
ds.setPassword("123456");***
首先我用的数据库是5.7.31版本的导入的mysql-connector-java是6.0.2版本的,那么当这样写数据库连接时就会有两处错误:
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.
那么这里的驱动不适用于此版本的数据库,把驱动改为com.mysql.cj.jdbc.Driver
即可
2、数据库驱动改对后就是URL的错误了报错信息为Mon Oct 12 10:20:07 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is 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.
高版本的数据库需要对ssl进行设置还有就是乱码问题将url改为jdbc:mysql://localhost:3306/jdbc?serverTimezone=UTC&useSSL=false
即可问题全部解决记录一下