You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Richard Chamberlain <ri...@sunsetandlabrea.com> on 2002/09/07 08:37:27 UTC
javax.servlet.ServletException: Name java:comp is not bound in this Context
Hello,
I'm struggling setting up a database resource.
I've copied the xml pretty much verbatim from the docs in the JNDI
Datasource HOW-TO.
However when I try and access the database I get a ServletException as
follows:
javax.servlet.ServletException: Name java:comp is not bound in this
Context
This is the code that gets the connection:
Context env=(Context) new InitialContext().lookup("java:comp/env");
DataSource source=(DataSource) env.lookup("jdbc/db-pool");
Connection conn=source.getConnection();
and this is from server.xml:
<Resource name="jdbc/db-pool"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/db-pool">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>testuser</value>
</parameter>
<parameter>
<name>password</name>
<value>mypassword</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/test?autoReconnect=true</value>
</parameter>
</ResourceParams>
and the web.xml file:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/db-pool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Please help!
Thanks,
Richard
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>