在Web应用中使用XML文件配置数据源
来源: 时间:06-12-30 点击: 点击这里收藏本文
*/
System.out.println("<br>ds: " + ds);
((BasicDataSource) ds).setUrl(databaseURL);
((BasicDataSource) ds).setUsername(this.databaseUser);
((BasicDataSource) ds).setPassword(this.databasePassword);
try {
int maxConnections = Integer.parseInt(this.getElementText(root,
MAX_CONNECTIONS));
((BasicDataSource) ds).setMaxActive(maxConnections);
} catch (Exception e) {
e.printStackTrace();
}
this.cleanup();
}
}
(2) 定义实现解析oracle数据源的实现类OracleConfig.java,内容如下:
/*
* Created on 2005-8-29
*
*parse the xml file of the oracle configure
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package zy.pro.wd.xml;
import javax.sql.DataSource;
import javax.servlet.ServletContext;
import oracle.jdbc.pool.OracleConnectionCacheImpl;
/**
* @author zhangyi
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class OracleConfig extends DataSourceConfig {
private static final String MAX_CONNECTIONS = "MaxConnections";
public void init(ServletContext ctx, String xmlFile) throws Exception {
super.init(ctx, xmlFile);
String databaseURL = "jdbc:oracle:thin:@" + this.serverName + ":"
+ this.portNumber + ":" + this.databaseName;
把此文章收藏到: