Women in Technology

Hear us Roar



Article:
  Creating a Web Application with Ant and Tomcat 4
Subject:   Name jdbc is not bound in this Context
Date:   2003-10-29 17:05:35
From:   anonymous2
Response to: Name jdbc is not bound in this Context

I've met same problem when I use 'mysql 4.1 server", "mysql-connector-java-3.0.9-stable-bin.jar", and "tomcat 4.1.27 web server".


Originally, I use JBuilder, mysql 4.1, tomcat 4.0 to test my pure 'servlets' web application and it works well.


After, I move my web application into pure Tomcat 4.1.27 and compiled with ant. Though "ant compile" and "ant install" are ok, but the a method call from servlet to database connection always fails.


The error message is "Couldn't open connection to database(in DBAgent): Name jdbc is not bound in this Context" in the db log file.


Those displays on the screen are
"HTTP Status 500 -


--------------------------------------------------------------------------------


type Exception report


message


description The server encountered an internal error () that prevented it from fulfilling this request.


exception


java.lang.NullPointerException


"


I can see the correct context for dataresource in http://localhost:8080/admin.


The lines I added to the server.xml are "
--------------
<!-- Dragon Context -->
<Context path="/dragon" docBase="dragon"
debug="5" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
timestamp="true"/>

<Resource name="jdbc/diary"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceLink name="jdbc/diary"
global="jdbc/diary"
type="javax.sql.DataSource" />


<ResourceParams name="jdbc/diary">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<!-- Class name for mm.mysql JDBC driver -->
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>


<!-- The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/diary?autoReconnect=true</value>
</parameter>


<!-- Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>

<!-- Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit.
-->
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>

<!-- Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>

<!-- MySQL dB username and password for dB connections -->
<parameter>
<name>username</name>
<value>root</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>

</ResourceParams>
</Context>
----------------------
Please help solve the problem.


Thanks a lot.


Julia Berlo