DriverManager 獲取數據庫鏈接

//基於DriverManager 的獲取數據庫鏈接
String user = null;
String password = null;
String jdbcUrl = null;
String driverClass = null;
//獲取配置文件
InputStream inputStream
        = getClass().getClassLoader().getResourceAsStream("jdbc.properties");
//讀取文件
Properties properties = new Properties();
properties.load(inputStream);//載入文件
user = properties.getProperty("user");
password = properties.getProperty("password");
jdbcUrl = properties.getProperty("jdbcUrl");
driverClass = properties.getProperty("driver");
//註冊數據庫驅動程序員
Class.forName(driverClass);
Connection connection = DriverManager.getConnection(jdbcUrl, user, password);
return connection;
相關文章
相關標籤/搜索