Monday, December 21, 2009

jdom Example

<?xml version="1.0" encoding="UTF-8"?>

<database>

<main id="jdbcconnecter">

<driver id="jdbc">oracle.jdbc.driver.OracleDriver</driver>

<url id="java mysql">jdbc:oracle:thin:@XXXXXXXX:XXX</url>

<username uname="defult">XXXX</username>

<password password="defult">XXX</password>

</main>

</database>

 








public void setConnectionData(){

try{
String filename ="dataconnect.xml";
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File(filename));
Element root = doc.getRootElement();
List servlets = root.getChildren("main");
Iterator i = servlets.iterator();
while (i.hasNext()) {
Element servlet = (Element) i.next();
driver= servlet.getChild("driver").getTextTrim();
url=servlet.getChild("url").getTextTrim();
username=servlet.getChild("username").getTextTrim();
password=servlet.getChild("password").getTextTrim();

}//end while


}catch(Exception e){
e.printStackTrace();
}


}

No comments: