Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Using DataStore in tomcat 5

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

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"
auth="Container"/>
<ResourseParams name="jdbc/HOMEACCOUNT_DBX">
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/HomeAccount_DB</value>
</parameter>
</ResourseParams>
</Context>

2. i introduce it to web.xml by

<resource-ref>
<res-ref-name>jdbc/HOMEACCOUNT_DBX</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>




3.i lookup it by this code


Context ctx = new InitialContext();
datasource = (DataSource) ctx.lookup
("java:comp/env/"+dataSourceJNDIName);
....
try {
return datasource.getConnection(); /* throws exception*/
}catch (Exception e){

4. Finally i receve this Exception

org.apache.commons.dbcp.SQLNestedException:
Cannot create JDBC driver of class '' for connect URL 'null'

Share: 

 

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"
debug="0"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
debug="0"/>

<!-- Global JNDI resources -->
<GlobalNamingResources>
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved">
</Resource>
<ResourceParams name="UserDatabase">
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>

</GlobalNamingResources>

<Service name="Catalina">
<Connector
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"
timestamp="true"/>

<!-- 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"
timestamp="true"/>
<Resource name="jdbc/SISSECDS" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/SISSECDS">
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>password</name>
<value>SISSEC</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:SISSEC/SISSEC@...:1521:ORALINUX</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>username</name>
<value>SISSEC</value>
</parameter>
</ResourceParams>
</Context>
</Host>

</Engine>

</Service>

</Server>

///////////////////////////////////////////////////////

Configuration of "server.xml"

Assumptions:
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>:

<Server>
<Service>
<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"/>
</Context>

...
</Engine>
</Service>
</Server>
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:

<web-app>
...

<resource-ref>
<description>MyApp DataSource Reference</description>
<res-ref-name>jdbc/MyappDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

...
</web-app>

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.




Tagged: