dbconfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<jdbc>
<param>
<name>oracle</name>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<url>jdbc:oracle:thin:@localhost:1521:lazy</url>
<uname>system</uname>
<password>lazy</password>
</param>
</jdbc>DBConfig.java
package com.toj.utils;import java.io.IOException;
import java.util.Iterator;import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;public class DBConfig {
private String url;
private String uname;
private String password;
private String name;
private String driver;
private String xmlsrc;

public String getDriver() {
return driver;
}
public String getName() {
return name;
}
public String getPassword() {
return password;
}
public String getUname() {
return uname;
}
public String getUrl() {
return url;
}
public String getXmlsrc() {
return xmlsrc;
}

public DBConfig(String name, String xmlsrc){
this.name = name;
this.xmlsrc = xmlsrc;
init();
}

private void init(){
try {
SAXBuilder s = new SAXBuilder();
Document doc = s.build(xmlsrc);
Element root = doc.getRootElement();
Iterator it = root.getChildren().iterator();
while(it.hasNext()){
Element tmp = (Element) it.next();
if(tmp.getChildText("name").equals(name)){
url = tmp.getChildText("url");
driver = tmp.getChildText("driver");
uname = tmp.getChildText("uname");
password = tmp.getChildText("password");
}
}
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}这是一个解析数据库连接的程序,你自己看,应该能明白。
需要引入jdom的jar包