Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Using DataStore in tomcat 5

  Asked By: Boell    Date: Aug 26    Category: Java    Views: 1483

IDE : JBuilder 2005
DBMS: MySql 3.23.45
Wb Server : JB embeded tomcat 5.0.27

1.i define my Datastore in server.xml

<Context debug="0" docBase="someAddress" path="/WebModule1"
reloadable="true" workDir="someAddress">
<Resourse name="jdbc/HOMEACCOUNT_DBX" type="javax.sql.DataSource"
<ResourseParams name="jdbc/HOMEACCOUNT_DBX">

2. i introduce it to web.xml by


3.i lookup it by this code

Context ctx = new InitialContext();
datasource = (DataSource) ctx.lookup
try {
return datasource.getConnection(); /* throws exception*/
}catch (Exception e){

4. Finally i receve this Exception

Cannot create JDBC driver of class '' for connect URL 'null'



3 Answers Found

Answer #1    Answered By: Kerry Wright     Answered On: Aug 26

You must be carefull where your Context tag is. This server.xml works for me. Context tag is inside Host tag.

<?xml version='1.0' encoding='utf-8'?>

<Server port="8005" shutdown="SHUTDOWN" debug="0">

<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"

<!-- Global JNDI resources -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<Resource name="UserDatabase" auth="Container"
description="User database that can be updated and saved">
<ResourceParams name="UserDatabase">


<Service name="Catalina">
port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" />
<Connector port="8009"
enableLookups="false" redirectPort="8443" debug="0"
protocol="AJP/1.3" />

<Engine name="Catalina" defaultHost="localhost" debug="0">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
debug="0" resourceName="UserDatabase"/>
<Host name="localhost" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="localhost_log." suffix=".txt"

<!-- Define properties for each web application. This is only needed
if you want to set non-default properties, or have web application
document roots in places other than the virtual host's appBase
directory. -->

<!-- tomcat  Root Context -->
<Context path="" docBase="ROOT" debug="0">

<Context path="/SISSECWeb" docBase="SISSECWeb"
debug="5" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_DBTest_log." suffix=".txt"
<Resource name="jdbc/SISSECDS" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/SISSECDS">





Configuration of "server.xml"

1) I assume that your application is named "myapp"
2) I assume that it resides under "{TOMCAT_HOME}/webapps/myapp/"
3) I assume that you want to connect to DBMS that is in your computer (localhost)
4) I assume that the name of the database you want to connect is "MyappDB"
5) I assume that you use mysql  JDBC driver

So put the following entry in "server.xml" under the tag <Engine>:


<Context docBase="mayapp" path="/myapp" workDir="work/Catalina/localhost/myapp">

<Resource auth="Container" description="MyApp DataSource Reference" name="jdbc/MyappDB" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" password="[i]your_password[/i]" maxIdle="2" maxWait="5000" username="[i]your_username[/i]" url="jdbc:mysql://localhost/MyappDB" maxActive="4"/>

Configuration of "web.xml"

To have well configurred "web.xml" file for your web app you should have the following entry under <web-app> tag:


<description>MyApp DataSource Reference</description>


Besids manual configuration you can use Tomcat's admin tool.

1) Login to the admin tool (http://localhost:8080/admin/)
2) Using the menu like browser expand the tree as follows:
"Tomcat Server->Service (Catelina)->Host (localhost)->Context (/myapp)-> Resources->"
3) Click on "Data Sources" and you should be able to the list of see your data sources
4) From Data Source Actions drop down lis (uper right in the eindow) select "Create New Data Source"

5) Fill the form as follows:
5.1) JNDI Name = jdbc/MyappDB
5.2) Data Source URL = jdbc:mysql://localhost/school
5.3) JDBC Driver Class = com.mysql.jdbc.Driver
5.4) User Name = your_username
5.5) Password = your_password
5.6) Max. Active Connections = 4
5.7) Max. Idle Connections = 2
5.8) Max. Wait for Connection = 5000
5.9) Validation Query =

6) Press the "Save" button (upper right)
7) Press "Commit Changes" button
8) Restart your Tomcat server

Answer #2    Answered By: Miriam Green     Answered On: Aug 26

it seems your MySql JDBC driver files are not
available in the place that it should be ,niether in
your classpath nor in your lib/ext of JRE.As the
result JDBC
driver couldn'd be loaded and u get the message.

Answer #3    Answered By: Alberta Miller     Answered On: Aug 26

Thanks for your help BUT I can connect to my DB with same setting by
Class.forname method (without using DataSource)
So I think that jdbc driver is not the problem.

Didn't find what you were looking for? Find more on Using DataStore in tomcat 5 Or get search suggestion and latest updates.