Dom4j + xpath configure Oracle database connection to read xml files

Source: Internet
Author: User
Today, with the help of the instance for configuring Oracle database connection, we will learn one way to read xml files (other reading methods will be introduced later): mdash; dom4j

Today, with the help of the instance for configuring Oracle database connection, we will learn one way to read xml files (other reading methods will be introduced later): mdash; dom4j

Today, with the help of the instance for configuring Oracle database connection, we will learn one way to read xml files (other reading methods will be introduced later)-using dom4j + xpath.

Dom4j is an open-source XML parsing package produced by dom4j.org. Therefore, the package "dom4j-1.6.1.jar" must be copied to the web-inf/lib.

We take the xpath method to look up, so we must copy the package "jaxen-1.1-beta-5.jar" to web-inf/lib as well. Otherwise, an exception occurs in java. lang. NoClassDefFoundError: org/jaxen/JaxenException.

Copy the preceding two packages to encode them:

1. The xml configuration file is as follows:




Oracle. jdbc. driver. OracleDriver
Jdbc: oracle: thin: @ localhost: 1521: bjpowernode
Lzq
Lzq

2. Because the configuration file contains drivers, URLs, user names, and passwords, multiple values must be returned after resolution. Therefore, we create a JdbcConfig object class and set the attributes as the above fields to store the information after parsing the xml file.

Package com. bjpowernode. drp. util;
/**
* Jbdc configuration information
* @ Author liuzhengquan
*/
Public class JdbcConfig {
@ Override
// Rewrite the toString Method
Public String toString (){
// The content of the method body is the same as that of the parent class.
// Return super. toString ();
Return this. getClass (). getName () + "{driverName:" + driverName +
", Url:" + url +
", Username:" + username +
", Password:" + password + "}";
}
Private String driverName;
Private String url;
Private String username;
Private String password;

// The following get and set methods can be automatically generated in myEclipse.
Public String getDriverName (){
Return driverName;
}
Public void setDriverName (String driverName ){
This. driverName = driverName;
}
Public String getUrl (){
Return url;
}
Public void setUrl (String url ){
This. url = url;
}
Public String getUsername (){
Return username;
}
Public void setUsername (String username ){
This. username = username;
}
Public String getPassword (){
Return password;
}
Public void setPassword (String password ){
This. password = password;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.