欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

tomcat中获取不同的数据源java代码 博客分类: java,tomcat,数据源 tomcatjavadatasource数据源 

程序员文章站 2024-02-11 17:54:52
...
LOG.debug("数据文件存入IC_CARD_POOL过程开始.................");

    String productNo = (String)ctx.getAttribute("product_no");

    long millis0 = System.currentTimeMillis();
    Integer batchNo = Integer.valueOf(Integer.parseInt(ctx.getJobNo()));
    String jobDate = (String)ctx.getAttribute("job_date");
    String companyNo = (String)ctx.getAttribute("companyNo");

    Connection connections = null;
    DataSource datasource = null;
    try
    {
      InitialContext namingContexts = new InitialContext();

      datasource = (DataSource)namingContexts.lookup("IC_DATASOURCE");
    } catch (NamingException e1) {
      e1.printStackTrace();
    }
    try {
      connections = datasource.getConnection();

      DateFormat f = new SimpleDateFormat("yyyyMMdd");
     
     
      其中IC_DATASOURCE在tomcat/conf中的context.xml中配置
      如下所示:
       <resource
                name="IC_DATASOURCE"
                type="javax.sql.DataSource"
    impl="org.apache.commons.dbcp.BasicDataSource"
                driverClassName="oracle.jdbc.driver.OracleDriver"
                url="jdbc:oracle:thin:@10.225.8.142:1521:iccard"
                username="tsmbat"
                password="tsmbat"
                maxIdle="200"
                maxWait="5000"
                maxActive="50"
                testOnReturn="true"
                testWhileIdle="true"
                testOnBorrow="true"
                validationQuery="SELECT COUNT(*) FROM DUAL"/>