标签:
public static Connection getConnection() throws Exception {
// 1. ???????????? 4 ?????.
// 1). ???? Properties ????
Properties properties = new Properties();
// 2). ??? jdbc.properties ???????????
InputStream in = JDBCTools.class.getClassLoader().getResourceAsStream(
"jdbc.properties");
// 3). ???? 2?? ???????????
properties.load(in);
// 4). ??????? user, password ??4 ?????.
String user = properties.getProperty("user");
String password = properties.getProperty("password");
String jdbcUrl = properties.getProperty("jdbcUrl");
String driver = properties.getProperty("driver");
// 2. ?????????????(????? Driver ??????????????????????.)
Class.forName(driver);
// 3. ??? DriverManager ?? getConnection() ???????????????.
return DriverManager.getConnection(jdbcUrl, user, password);
}
标签:
原文地址:http://www.cnblogs.com/taz372436/p/5593213.html