数据库连接方式
1、连接方式一
显式出现了第三方数据库的API
@Test
public void testConnection1() throws SQLException {
//1.提供java.sql.Driver接口实现类的对象
Driver driver = new com.mysql.cj.jdbc.Driver();
//2.提供url,指明具体操作的数据
String url = "jdbc:mysql://localhost:3306/atguigudb";
//3.提供Properties的对象,指明用户名和密码
Properties info = new Properties();
info.setProperty("user","root");
info.setProperty("password","root");
Connection conn = driver.connect(url, info);
System.out.println(conn);
}
2、连接方式二
相较于方式一,这里使用反射实例化Driver,不在代码中体现第三方数据库的API。体现了面向接口编程思想。
@Test
public void testConnection2() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
Cla