Configuring jdbc-pool (tomcat 7)
i'm having some problems with tomcat 7 for configuring jdbc-pool : i`ve tried to follow this example: http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdb开发者_如何学Goc-pool-high-concurrency
so i have:
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>
and when i try to do this:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource datasource = (DataSource)envContext.lookup("jdbc/LocalDB");
Connection con = datasource.getConnection();
i keep getting this error:
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)
pls help tnx
<Context> <ResourceLink type="javax.sql.DataSource" name="jdbc/LocalDB" global="jdbc/DB"/>
replace that name="jdbc/LocalDB"
with name="jdbc/DB"
in your context.xml
and
(DataSource)envContext.lookup("java:/comp/env/jdbc/DB");
[the second line of code is redundant].
Change the Following line in server.xml use type="org.apache.tomcat.jdbc.pool.DataSource" instead of type="javax.sql.DataSource"
and use (DataSource)envContext.lookup("java:/comp/env/jdbc/LocalDB") instead of DataSource)envContext.lookup("java:/comp/env/jdbc/DB") in your program, then you will get DBConnectoin.
conf/server.xml and conf/context.xml...
do you have it inside tomcat installation prefix? on eclipse i have my context inside WebContent/META-INF, and server.xml inside Server project; on resulting war context.xml got inside the correct META-INF
in the end i have everything like your configs, except that i don't know where you're placing that context.xml.
also, i've made as @Henry suggested too, but with some luck your problem is just the location of context.xml
精彩评论