标签:
//config.properties中配置了数据库配置的相关信息,通过这个单例模式设计来实现解耦。
public class PathConfig {
private static PathConfig instance = null;
private String dataPath = null;
private PathConfig(){
InputStream in = getClass().getResourceAsStream("/config.properties");
Properties p = new Properties();
try {
p.load(in);
url = p.getProperty("DBURL", "");
username = p.getProperty("DBUSER", "");
password = p.getProperty("DBPASS", "");
}catch(IOException e){
e.printStackTrace();
}
}
public static synchronized PathConfig getInstance(){
if(instance == null){
instance = new PathConfig();
}
return instance;
}
}
config.properties:
DBURL=jdbc:oracle:thin:@xxx.xxx.x.x:1521:XE DBUSER=xxxxx DBPASS=xxxxx
标签:
原文地址:http://www.cnblogs.com/sunyt/p/4355672.html