JDBC连接数据库的五种方式
1.使用Driver连接:
public void con1() throws Exception {
// 获取驱动
Driver driver = new Driver();
String url = "jdbc:mysql://localhost:3306/hsp_db02";
Properties properties = new Properties();
properties.setProperty("user", "root");
properties.setProperty("password", "abc123");
// 链接数据库
Connection connect = driver.connect(url, properties);
// 关闭数据库连接
connect.close();
}
2.使用反射连接:
public void con2() throws Exception {
// 得到驱动文件