漫步红林

品味技术与生活之间的差距,追求代码与国画之间的艺术.

BlogJava 联系 聚合 管理
  0 Posts :: 28 Stories :: 2 Comments :: 0 Trackbacks
 1<!-- Context.xml -->
 2<Resource
 3      name="jdbcSource_1"
 4      type="javax.sql.DataSource"
 5      password="we0801"
 6      driverClassName="oracle.jdbc.driver.OracleDriver"
 7      maxIdle="2"
 8      maxWait="5000"
 9      username="we0801"
10      url="jdbc:oracle:thin:@192.168.1.100:1521:booleanlab"
11      maxActive="4"/>
12
13<!-- web.xml -->
14
15  <resource-ref>
16   <res-ref-name>jdbcSource_1</res-ref-name>
17   <res-type>javax.sql.DataSource</res-type>
18<res-auth>Container</res-auth>
19  </resource-ref>
20
21<!-- 获得数据源 -->
22public Connection getConnection(){
23  Connection con = null;
24  Context ctx = null;
25  DataSource ds= null;
26  try {
27   ctx = new InitialContext();
28   ds = (DataSource) ctx.lookup("java:comp/env/jdbcSource_1");   
29   con = ds.getConnection();
30  }
 catch (NamingException e) {
31   e.printStackTrace();
32  }
 catch (SQLException e) {
33   e.printStackTrace();
34  }

35  return con;
36}
 
posted on 2009-02-22 18:23 苦瓜 阅读(186) 评论(0)  编辑  收藏 所属分类: Tomcat

只有注册用户登录后才能发表评论。


网站导航: