我遇到了一些問題和Tomcat 7的配置JDBC池:i`ve試圖以此爲榜樣:http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency配置JDBC池(Tomcat的7)
,所以我有:
的conf/server.xml中
<GlobalNamingResources>
<Resource type="javax.sql.DataSource"
name="jdbc/DB"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mydb"
username="user"
password="password"
/>
</GlobalNamingResources>
conf/context.xml文件
<Context>
<ResourceLink type="javax.sql.DataSource"
name="jdbc/LocalDB"
global="jdbc/DB"
/>
<Context>
,當我嘗試這樣做:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource datasource = (DataSource)envContext.lookup("jdbc/LocalDB");
Connection con = datasource.getConnection();
我不斷收到此錯誤:
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:803)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
請幫助 TNX