文件 jdbc.properties 的内容:
工具类:
/**
* 获取 Properties 文件对象的工具类
*/
public class PropertiesUtil {
//私有化构造方法
private PropertiesUtil() {
}
private static Properties properties = null;
/**
* 不传参数则默认获取 jdbc.properties 文件
* @return
*/
public static Properties getProperties() {
return getProperties("jdbc.properties");
}
public static Properties getProperties(String fileName) {
if (properties == null) {
properties = new Properties();
try {
properties.load(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName));
} catch (IOException e) {
e.printStackTrace();
}
}
return properties;
}
}