标题问题描述:
本人在学习尚硅谷的JDBC课程时,在获取数据库连接时,出现了问题
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.
出现此问题的代码如下所示,JDK版本是Azul Zulu version 17.0.1,MySQL版本是8.0.27
package com.connectionTest;
import org.junit.Test;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Properties;
public class Connection_test {
@Test
public void testConnection1() throws SQLException {
/*
jdbc:mysql:协议
localhost:ip地址
3306:默认端口号
test:test数据库
*/
Driver driver = new com.mysql.jdbc.Driver();
String url = "jdbc:mysql://localhost:3306/atguigudb";
Properties info = new Properties();
info.setProperty("user", "root");
info.setProperty("password","");
Connection conn = driver.connect(url, info);
System.out.println(conn);
}
}
解决办法
刚看到问题会比较懵,怀疑自己的操作是否跟康老师不一样,hh。其实是因为com.mysql.jdbc.Driver被替换成了com.mysql.cj.jdbc.Driver