DriverManager 是驱动的管理类:
1)可以通过重载的getConnection()方法获取数据库连接,较为方便
2)可以同时管理多个驱动程序:若注册了多个数据库连接,则调用getConnection()方法时传入的参数不同,即返回不同的数据库连接。
DriverManaer学习代码:
public class TestConnection {
public void testDriver() throws Exception {
//1.创建一个Driver 实现类的对象
Driver driver = new com.mysql.cj.jdbc.Driver();
//2.准备连接数据库的基本信息:url,user,password
String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
Properties info = new Properties();
info.put("user", "root");
info.put("password", "zjxjq88394722");
//3.调用Driver 接口的 connect(url,info)获取数据库连接
Connection connection = driver.connect(url, info);
System.out.println(connection);
}
//通