c3po数据库连接池中取出连接
<!-- 使用连接池获得连接JNDI java name dri interface java命名目录接口 --> <!-- 获得连接 --> <% Context context = new InitialContext(); DataSource ds = (DataSource)context.lookup("java:/comp/env/jdbc/oracle"); Connection conn = ds.getConnection(); PreparedStatement ps = conn.prepareStatement("select * from teleinfo"); ResultSet rs = ps.executeQuery(); while(rs.next()) { out.println(rs.getString(3)); out.println(); } conn.close(); %>
在应用的 context.xml 中如下配置:
<Context> ..... ..... <Resource name="jdbc/oracle" auth="Container" type="javax.sql.DataSource" maxActive="4" maxIdle="2" maxWait="5000" username="telecom" password="orcl" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:ORCL"/> </Context>
每一天的成长!