赞
踩
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 {
// 得到驱动文件
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。