您的位置:首页 > 运维架构 > Tomcat

配置Tomcat数据源和连接池

2008-09-23 10:41 501 查看
修改C:/Tomcat 6.0/conf/context.xml,在<Context></Context>之间加入:

<Resource name="jdbc/bizapp" 
type="javax.sql.DataSource"
password="gps"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxIdle="30" 
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
maxWait="10000"
username="navtech"
url="jdbc:oracle:thin:@90.0.12.10:1521:NAVTECH" maxActive="500"/>

 

引用:java:comp/env/jdbc/bizapp

你可以将此语句写入资源文件Connection.properties中:

datasourcename=java:comp/env/jdbc/bizapp

使用:

     try {
      InputStream is = getClass().getResourceAsStream("/Connection.properties");
      Properties dbProps = new Properties();
         dbProps.load(is);  
      Context initCtx = new InitialContext();
      this.dataSource=(DataSource)initCtx.lookup(dbProps.getProperty("datasourcename"));
     } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 

 

    public Connection getConnection(){
        Connection con = null;
        try{
            con = this.dataSource.getConnection();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return con;
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息