jdbc连接参数的抓取
private static final String PROPERTIES_FILE = "WEB-INF/conf/config.properties";
/**
* 得到配置文件路径,并读出jdbc的参数
*/
String propertiesFile = request.getServletContext().getRealPath(PROPERTIES_FILE);
InputStream is = new FileInputStream(propertiesFile);
properties.load(is);
String url = null;
String username = null;
String password = null;
String drivers = properties.getProperty("dbDriver");
if (drivers != null) {
url = properties.getProperty("dbURL");
username = properties.getProperty("user");
password = properties.getProperty("password");
}
Class.forName(drivers); // 注册驱动
Connection conn = DriverManager.getConnection(url, username, password);// 数据库连接