精彩专题推荐:建站之入门课 建站之必修课 建站之关键课 网站价值所在 流量提高专题 css+div 标准 个人网站打造全过程
返回建站学首页
导航:
建站首页 | 网站设计 | 网站开发 | 网站运营 | 网页软件 | 建站指南 | 搜索优化 | 图像处理 | 视频教程 | 书籍教程 | 建站专题
当前位置:首页>网站开发>xml教程>正文

在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;
9 7 3 1 2 3 4 5 6 7 8 9 10 4 8 :

  把此文章收藏到:          
广而告之
文章搜索
  • Google JZxue.Com

关于我们 | 联系我们 | 友情链接 | 网站地图
Copyright © 2005 - 2006 建站学 All rights reserved.