功夫没有捷径

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
//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

 

posted on 2015-03-21 15:27  Juniors  阅读(415)  评论(0编辑  收藏  举报