Java读取Xml

阅读更多
public void done() {
File xmlfile = new File((new File("").getAbsolutePath())
+ "/WebRoot/DBconfig.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Document Doc = null;
try {
Doc = builder.parse(xmlfile);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Driver = Doc.getElementsByTagName("driver").item(0).getFirstChild()
.getNodeValue();
URL = Doc.getElementsByTagName("URL").item(0).getFirstChild()
.getNodeValue();
username = Doc.getElementsByTagName("username").item(0).getFirstChild()
.getNodeValue();
pwd = Doc.getElementsByTagName("pwd").item(0).getFirstChild()
.getNodeValue();
testsql = Doc.getElementsByTagName("testsql").item(0).getFirstChild()
.getNodeValue();
System.out.println("Driver:->" + Driver + "\nURL:->" + URL
+ "\n用户名:->" + username + "\n密码:->" + pwd + "\ntestsql:"
+ testsql);
}













oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:@127.0.0.1:1521:ZWM

a

a

select sysdate from dual

你可能感兴趣的:(XML,Java,Oracle,JDBC,SQL)