java基础-jdbc——三种方式加载驱动建立连接

时间:2021-10-30 23:38:09
 String url = "jdbc:mysql://localhost:3306/student?Unicode=true&characterEncoding=utf-8";
Properties info = new Properties();
info.put("user", "canon");
info.put("password", "123456"); /**
* 三种方式加载驱动建立连接
*/
//方式1
Driver driver = new com.mysql.jdbc.Driver();
Connection connection = driver.connect(url, info); /*
//方式2
Driver driver = DriverManager.getDriver(url);
connection = driver.connect(url, info); //方式3
Class.forName(url);
conn = DriverManager.getConnection(url, info);
*/