通过返回Connection对象实现连接数据库
- 定义相关变量:
user
password
classDriver
properties
inputstream
connection
driver
url
- 通过反射获取输入流读取properties文件
inputStream=getClass().getClassLoader().getResourceAsStream(“配置文件”);
- 给上述变量赋值
- Properties.put(“user”,user)….
- 通过反射new一个Driver类的对象
driver = (Driver) Class.forName(classDriver).newInstance();
- 获取connection
connection = driver.connection(url,properties);