首页>代码>java开发Web版本ip登记管理系统软件源码>/xipv/src/com/bjpowernode/drp/ConfigReader.java
package com.bjpowernode.drp;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * 采用单例模式读取xml配置文件sys-config.xml
 * @author Administrator
 *
 */
public class ConfigReader {

	private static ConfigReader instance = new ConfigReader();
	
	private Document doc;
	
	private JdbcInfo jdbcInfo;
	
	private ConfigReader() {
		try {
			doc = new SAXReader().read(Thread.currentThread().getContextClassLoader().getResourceAsStream("sys-config.xml"));
			Element driverNameElt = (Element)doc.selectObject("/config/db-info/driver-name");
			Element urlElt = (Element)doc.selectObject("/config/db-info/url");
			Element usernameElt = (Element)doc.selectObject("/config/db-info/username");
			Element passwordElt = (Element)doc.selectObject("/config/db-info/password");
			jdbcInfo = new JdbcInfo();
			jdbcInfo.setDriverName(driverNameElt.getStringValue());
			jdbcInfo.setUrl(urlElt.getStringValue());
			jdbcInfo.setUsername(usernameElt.getStringValue());
			jdbcInfo.setPassword(passwordElt.getStringValue());
			//-------------------------------------------------------------
		} catch (DocumentException e) {
			e.printStackTrace();
		}
	}
	
	public static ConfigReader getInstance() {
		return instance;
	}
	
	public JdbcInfo getJdbcInfo() {
		return jdbcInfo;
	}
	
	public static void main(String[] args) {
	}
}
最近下载更多
gogola  LV1 2022年3月17日
coolliyi  LV1 2022年1月27日
1760014638  LV1 2022年1月4日
nsz123456  LV11 2021年12月5日
yqzzcj  LV1 2021年9月9日
zm312463  LV1 2021年4月20日
徐梓轩  LV8 2020年11月16日
putifeishu108  LV7 2020年8月11日
Crrrrryttt  LV3 2020年6月2日
自行车_1  LV7 2020年4月17日
最近浏览更多
WBelong  LV7 2023年12月18日
G0200887 2023年10月22日
暂无贡献等级
暂无贡献等级
wbx666  LV1 2023年9月18日
asadda  LV2 2023年6月27日
pangzhihui  LV12 2023年6月2日
1073931745  LV1 2022年12月13日
微信网友_6248713511227392  LV11 2022年12月5日
xiaocao01  LV2 2022年10月10日
yuning47  LV2 2022年10月3日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友