日期:2014-05-20 浏览次数:20920 次
<Resource name="ccpa" auth="Container" type="javax.sql.DataSource" driverClass="oracle.jdbc.driver.OracleDriver" username="postaudit" password="paea" jdbcUrl="jdbc:oracle:thin:@127.0.0.1:1521:ccpa" idleConnectionTestPeriod="0" idleMaxAge="60" partitionCount="1" maxConnectionsPerPartition="5" minConnectionsPerPartition="2" acquireIncrement="2" poolAvailabilityThreshold="20" connectionTimeout="60000" />
<resource-ref> <description>DB Connection</description> <res-ref-name>ccpa</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref>
//连接数据库 public Connection getConnection(){ Connection conn=null; try { String jndi="ccpa"; Context ctxt=new InitialContext(); DataSource ds=(DataSource) ctxt.lookup(jndi); System.out.println("XXXXXXXXXXXXXXX"+ds); try { conn=ds.getConnection(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (NamingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; }
javax.naming.NameNotFoundException: Name ccpa is not bound in this Context at org.apache.naming.NamingContext.lookup(NamingContext.java:770) at org.apache.naming.NamingContext.lookup(NamingContext.java:153) at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152) at javax.naming.InitialContext.lookup(InitialContext.java:392)
<Context path="/myweb" docBase="web1" debug="0" crosscontext="true" reloadable="true"> <Resource name="jdbc/sample_db" auth="Container" type="javax.sql.DataSource" maxActive="20" maxIdle="5" maxWait="10000" username="postaudit" password="paea" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@127.0.0.1:1521:ccpa"/> </Context>