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

Hi Everyone!

I am placing this journal entry here to hopefully be of some assistance to anyone who is running into this situation as I did when trying to deploy a JSC app to tomcat 5.5.17 using a jdbc connection.

I'm sure I don't need to explain how difficult it was to find help and how much time I spend trying to solve the problem. However for the sake of making this article "find-able" here is the error that you are most likely you are querying the forum for...

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

alright on the steps that worked for me and hopefully will work for you!

Note the driver I am using is the jTDS driver which can be found @ http://jtds.sourceforge.net/ this is a great driver, speedy and with good documentation!

Below are the steps I followed to successfully deploy a jdbc jsc app to tomcat

- Export your application from JSC as a war file by right clicking on the project node and then selecting "Export WAR File" from the context menu. Note these steps are for exporting web apps to J2EE 1.4 specifications.

- Now that you have exported the WAR file copy it from where ever you save it and place it in the webapps folder of your tomcat folder. For example I copied my ssaer.WAR file to : C:\Documents and Settings\billyd\My Documents\Tomcat 5.5\webapps\. The configuration for auto deploy in tomcat is outside the scope of howto so please go to apache.org to find configuration instructions for tomcat.

- Stop the tomcat service and and restart it to auto deploy the WAR file. Now copy the jdbc driver to the web-inf folder of your application, in my case I copied the jtds-1.2.jar to C:\Documents and Settings\billyd\My Documents\Tomcat 5.5\webapps\ssaer\WEB-INF\lib\

Note I had also previously copied that file to the C:\Documents and Settings\billyd\My Documents\Tomcat 5.5\common\lib\ I have since left it there and I'm sure its not hurting anything so for good measure also copy it there...

almost to the point where you can breath a sigh of relief...

- Now through the admin web app for tomcat you will configure the JDNI Data Source entry for your app. If you do not have admin web app for tomcat now is a good time to download it and again this is outside the scope of the howto. However if you have to download I will save you some time... Make sure that once its installed you configure a user in the \Tomcat 5.5\conf\tomcat-users.xml file. Add a line like this

<user username="root" password="root" roles="admin,manager"/> user name and password is up to you, I was lazy and I used the same value for the user and password because this is a dev system NEVER BE LAZY IN PROD SYSTEMS.

- In the admin web app on the left expand the the "Tomcat Server" node, then expand the "Service (Catalina)" node. Expand the "HOST (localhost)" node. A list of applications will appear, find your context, in my case my context is (/ssaer). Expand your context and then expand the resources node. There you will see the Data Source node, click it. Hopefully the main window will show the data source reference you declared in the JSC project. I named my data source reference as eridb and I was presented with a jdbc/eridb under my JDNI Name column. The JDBC Drive Class column was empty as yours should be.

- Click the JDNI Name entry and configure it. If you are not sure what goes where in your JSC ide click on the servers tab and right click your data source node and chose "Export Data Source" from the context menu. The resulting xml file will contain the connection string you can use in this step.

- Once you have completed the above step click on save and then on commit. Wait a minute and make a JDNI name entry with the same exact name in the resources node of the main server. this is a good measure step. Once that is done save and commit and finally restart the tomcat server.

Hopefully by now your app should be working and you are doing the sigh of relief thing....

Couple of things to note I had copied other files to the \Tomcat 5.5\common\lib folder such as the jstl.jar and the standard.jar. JSC has a very straight forward help for export to tomcat and it contains the links to the projects that will have the jars needed to make your application work in tomcat.

Hope this helps!

[4433 byte] By [bilorge] at [2007-11-26 8:33:03]
# 1
Thanks for sharing this information!Best Regards,Sakthi
sakthivelgopal at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 2
great answer from a smart fellow, thanks for the accurate concise information, it works now.
hah0569 at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 3

hello,

I had the same problem.

your solution is very well.

i think you must habe a special xml-attribute order:

<Resource

auth="Container"

description="DB Connection"

name="jdbc/oracle"

type="javax.sql.DataSource"

driverClassName="oracle.jdbc.OracleDriver"

password="password"

maxIdle="2"

maxWait="5000"

username="user"

url="jdbc:oracle:thin:@db:1521:name"

maxActive="4"/>

its not working if you put this element below <GlobalNamingResources> !

you have to put this <Resource> to your <Context>

HolgerCosys at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 4
Thanks thanks thanks a lot.... i'm crying for 5 days... until reading this post.Thanks a loooooooot!Ebolo.
Ebolo at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 5

Thanks SO Much for this. This article helped me a LOT. I've been struggling for SO long. Thanks and may Jesus bless you :) I'm just SO happy that it works now.

I only had to copy the ms*.jar (3) files to the common\lib\ of Tomcat 5. Then I had to restart (VERY IMPORTANT) the server and then it worked.

Also make sure the URL is something like: jdbc:microsoft:sqlserver://10.0.0.7:1433;DatabaseName=HealthCare;SelectMethod=c ursor

And the driver must be something like:

com.microsoft.jdbc.sqlserver.SQLServerDriver

Thanks a MILLION!

mpraath at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 6
Would anyone know if the same steps using an oracle driver would work for the same problem?
InfoSysExperts at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 7
I believe, this should work for Oracle driver as well.This works for MySQL and Derby on tomcat.-Sakthi
sakthivelgopal at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 8

Yes, this should work well for Oracle and for any JDBC compliant driver. The error extend from the app server not being able to locate the declared driver to communicate with the database. Don't forget to include the support libraries mentioned at the end of the article. Hope this helped you out a bit.

Cheers!

B

bilorge at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 9

To deploy the app developed in JSC that uses a datasource, as per your advice, I have downloaded the file "apache-tomcat-5.5.17-admin.zip" in order to perform admin work on the tomcat 5.5.17 server to change the datasource settings. After extracting the files from the zip, I couldn't find an install or a setup program. Could someone help me in this regard or suggest an admin-tool that i could download/use. I have sent couple of emails to tomcat sites and have posted the same request in the tomcat-forum too, but in vain. As the matter is pretty urgent now, I would appreciate any kind of help. Note that apps developed in JSC without a datasource works fine.

marysam at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 10

marysam,

Its a real simple thing, so much so that I was in the same situation when I first ran into this situation. The Tomcat admin web app is a module that you load to Apache. All you have to do is unzip the files into the proper directory and restart apache. I honestly dont remember how good was the documentation that came with the web apps, but its not that hard to deduce where they go in the directory structure of the application.

B

bilorge at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 11

Dear Billy

Thanx a lot. After some experimentation I managed to get the Tomcat's admin work and also migrated a pretty complex 25 pages/39 Dataproviders (that used Derby's SQL capabilities to its tortuous limits) system created using the JSC to Tomcat 5.5.17 and its working without a hitch. However, as a final piece of work, before I recommended the JSC as a must in our Java curriculum, I have to some how use MySql 5.0 instead of the embedded Derby. While MySql 5.0 presents no problems in JSC during building and testing, I have the following to recon with. I don't know what mistakes I have made. Could you please help me, which would enable me round up my report work. One word about the JSC and the Sun Team; both are wonderful. The Sun Team deserve public recognition and praise for creating the Creator, a real piece of art.

Although I have posted this as http://forum.java.sun.com/thread.jspa?threadID=5114077&tstart=15, for your convenience, I have pasted the same below:

Thanx in advance

I built a simple test app in JSC with MySql.

Product: MySql Ver. 5.0.27-community-nt

Database name: Test

Table name: testtable

Datasource name: MySql1

Dataprovider's SQL: SELECT ALL testtable.code, testtable.name FROM testtable WHERE testtable.name LIKE ?

The page had a textfield, button, statictext and a table mapped to the dataprovider

The following code was included:

public void prerender() {

try {

String s = "";

String t = (String) textField1.getText();

if (t == null || t.equals(""))

s = "";

else

s = t;

s += "%";

staticText3.setText(s);

getSessionBean1().getTesttableRowSet().setObject(1,s);

getSessionBean1().getTesttableDataProvider().refresh();

} catch (Exception e) {error(e.toString());}

}

public String button1_action() {

return null;

}

When tested in JSC, it worked fine.

But when I exported it as a war file and deployed it in Tomcat 5.5.17 with the following settings, the statictext displayed the selected value, but the table showed "No items found". Please help.

User: root

password: adminadmin

Connector downloaded: mysql-connector-java-5.0.4.zip

The appropriate jstl.jar and standard.jar where used by copying them from jakarta

The tomcat's server.xml used is shown below:

<?xml version="1.0" encoding="UTF-8"?>

<Server>

<Listener className="org.apache.catalina.core.AprLifecycleListener"/>

<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>

<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>

<GlobalNamingResources>

<Environment

name="simpleValue"

type="java.lang.Integer"

value="30"/>

<Resource

auth="Container"

description="User database that can be updated and saved"

name="UserDatabase"

type="org.apache.catalina.UserDatabase"

pathname="conf/tomcat-users.xml"

factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>

<Resource

name="jdbc/Travel"

type="javax.sql.DataSource"

driverClassName="org.apache.derby.jdbc.ClientDriver"

password="travel"

maxIdle="2"

maxWait="5000"

validationQuery="select * from TRAVEL.PRODUCT"

username="travel"

url="jdbc:derby://localhost:21527/samp"

maxActive="4"/>

</GlobalNamingResources>

<Service

name="Catalina">

<Connector

port="8080"

redirectPort="8443"

minSpareThreads="25"

connectionTimeout="20000"

maxThreads="150"

maxSpareThreads="75">

</Connector>

<Connector

port="8009"

redirectPort="8443"

protocol="AJP/1.3">

</Connector>

<Engine

defaultHost="localhost"

name="Catalina">

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>

<Host

appBase="webapps"

name="localhost">

<Context

path="/TomTest">

</Context>

<Context

path="/TradeMeTender">

<Resource

auth="Container"

description="Creator generated DataSource Reference"

name="jdbc/Travel"

type="javax.sql.DataSource"

driverClassName="org.apache.derby.jdbc.ClientDriver"

password="travel"

maxIdle="2"

maxWait="5000"

validationQuery="SELECT * from TRAVEL.PRODUCT"

username="travel"

url="jdbc:derby://localhost:21527/sample"

maxActive="4"/>

</Context>

<Context

path="/FileUploadExample">

<EJB

home="greeting.GreeterHome"

name="GreeterEJB"

remote="greeting.Greeter"

type="Session"/>

</Context>

<Context path="/MySqlTest" docBase="MySqlTest"

debug="5" reloadable="true" crossContext="true">

<Resource name="jdbc/MySql1" auth="Container" type="javax.sql.DataSource"

maxActive="100" maxIdle="30" maxWait="10000"

username="root" password="adminadmin" driverClassName="com.mysql.jdbc.Driver"

url="jdbc:mysql://localhost:3306/Test?autoReconnect=true"/>

</Context>

</Host>

</Engine>

</Service>

</Server>

marysam at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 12

Dear Billy

Thanx a lot. After some experimentation I managed to get the Tomcat's admin work and also migrated a pretty complex 25 pages/39 Dataproviders (that used Derby's SQL capabilities to its tortuous limits) system created using the JSC to Tomcat 5.5.17 and its working without a hitch. However, as a final piece of work, before I recommended the JSC as a must in our Java curriculum, I have to some how use MySql 5.0 instead of the embedded Derby. While MySql 5.0 presents no problems in JSC during building and testing, I have the following to recon with. I don't know what mistakes I have made. Could you please help me, which would enable me round up my report work. One word about the JSC and the Sun Team; both are wonderful. The Sun Team deserve public recognition and praise for creating the Creator, a real piece of art.

Althogh I have posted this as http://forum.java.sun.com/thread.jspa?threadID=5114077&tstart=15, for your convenience, I have pasted the same below:

Thanx in advance

I built a simple test app in JSC with MySql.

Product: MySql Ver. 5.0.27-community-nt

Database name: Test

Table name: testtable

Datasource name: MySql1

Dataprovider's SQL: SELECT ALL testtable.code, testtable.name FROM testtable WHERE testtable.name LIKE ?

The page had a textfield, button, statictext and a table mapped to the dataprovider

The following code was included:

public void prerender() {

try {

String s = "";

String t = (String) textField1.getText();

if (t == null || t.equals(""))

s = "";

else

s = t;

s += "%";

staticText3.setText(s);

getSessionBean1().getTesttableRowSet().setObject(1,s);

getSessionBean1().getTesttableDataProvider().refresh();

} catch (Exception e) {error(e.toString());}

}

public String button1_action() {

return null;

}

When tested in JSC, it worked fine.

But when I exported it as a war file and deployed it in Tomcat 5.5.17 with the following settings, the statictext displayed the selected value, but the table showed "No items found". Please help.

User: root

password: adminadmin

Connector downloaded: mysql-connector-java-5.0.4.zip

The appropriate jstl.jar and standard.jar where used by copying them from jakarta

The tomcat's server.xml used is shown below:

<?xml version="1.0" encoding="UTF-8"?>

<Server>

<Listener className="org.apache.catalina.core.AprLifecycleListener"/>

<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>

<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>

<GlobalNamingResources>

<Environment

name="simpleValue"

type="java.lang.Integer"

value="30"/>

<Resource

auth="Container"

description="User database that can be updated and saved"

name="UserDatabase"

type="org.apache.catalina.UserDatabase"

pathname="conf/tomcat-users.xml"

factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>

<Resource

name="jdbc/Travel"

type="javax.sql.DataSource"

driverClassName="org.apache.derby.jdbc.ClientDriver"

password="travel"

maxIdle="2"

maxWait="5000"

validationQuery="select * from TRAVEL.PRODUCT"

username="travel"

url="jdbc:derby://localhost:21527/samp"

maxActive="4"/>

</GlobalNamingResources>

<Service

name="Catalina">

<Connector

port="8080"

redirectPort="8443"

minSpareThreads="25"

connectionTimeout="20000"

maxThreads="150"

maxSpareThreads="75">

</Connector>

<Connector

port="8009"

redirectPort="8443"

protocol="AJP/1.3">

</Connector>

<Engine

defaultHost="localhost"

name="Catalina">

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>

<Host

appBase="webapps"

name="localhost">

<Context

path="/TomTest">

</Context>

<Context

path="/TradeMeTender">

<Resource

auth="Container"

description="Creator generated DataSource Reference"

name="jdbc/Travel"

type="javax.sql.DataSource"

driverClassName="org.apache.derby.jdbc.ClientDriver"

password="travel"

maxIdle="2"

maxWait="5000"

validationQuery="SELECT * from TRAVEL.PRODUCT"

username="travel"

url="jdbc:derby://localhost:21527/sample"

maxActive="4"/>

</Context>

<Context

path="/FileUploadExample">

<EJB

home="greeting.GreeterHome"

name="GreeterEJB"

remote="greeting.Greeter"

type="Session"/>

</Context>

<Context path="/MySqlTest" docBase="MySqlTest"

debug="5" reloadable="true" crossContext="true">

<Resource name="jdbc/MySql1" auth="Container" type="javax.sql.DataSource"

maxActive="100" maxIdle="30" maxWait="10000"

username="root" password="adminadmin" driverClassName="com.mysql.jdbc.Driver"

url="jdbc:mysql://localhost:3306/Test?autoReconnect=true"/>

</Context>

</Host>

</Engine>

</Service>

</Server>

marysam at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 13

marysam,

Let me try to duplicate your situation. I have since migrated to Netbeans 5.5 with the visual web pack and have made a couple of apps with it using MySQL 5 with no problems. I know there are subtle differences between the 2 IDEs. I should have some time tonight to review it.

B

bilorge at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 14

Billy

Thanx a lot for your reply and thanx for spending time on this issue. Take your time Billy and we both hope you'll find a solution to our problem. Otherwise, we have tested almost all aspects/features of JSC and we are very happy with it. Whatever we needed/wanted, such as Web Services, EJB and what not, everything in one pack! If you could pull us out of, hopefully, the last problem, you would have significantly contributed towards opening many gates in Auckland & Wellington.

Mary & Sam

marysam at 2007-7-6 21:58:08 > top of Java-index,Development Tools,Java Tools...
# 15

Marysam

I can't remember the exact details why but some months ago i rejected the MySql 5.x Driver. I'm pretty sure it was some odd irritating behavior similar to what you describe. Might I suggest you try the 3.1.12 or similar driver that I'm using right now with Tomcat 5.5.17 and having no problems...

I think issues with the 5.x driver have been reported on this forum in the past too.

yossariana at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...
# 16
Thanx for the reply and advice. As per your advice, I downloaded & tried 3.1.14, as I couldn't get 3.1.12. The problem still remains. I look forward to your reply.Mary
marysama at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...
# 17

A problem I experienced moving over to a remote server was MySql's case sensitivity. MySql has different defaults based on the underlying OS. It's not clear if you are trying to deploy to Tomcat on a remote machine or not... What I can say is that the Tomcat 5.5.17 / MySql 5 / jdbc 3.1.12 Driver definitely does work for me.

If none of this rings a bell could you post a little more detail on your setup / any messages / error logs etc. Also please use the code /code (in square brackets) tags -- it makes xml files and java code a lot easier to read.

yossariana at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...
# 18

MySql 5.0 is running on the same machine at port 3306, which works fine with the JSC. I transported the war file from the JSC to Tomcat and deployed the simple webapp in Tomcat. As you see from the code, to start with, the prerenderer passes '%' to the SQL to display all records. There were no messages or errors displayed. I have also examined all the server logs and there seem to be no starttup or runtime errors, and that is the reason I'm gropping in the dark. I couldn't even see a flicker of the table control that got stuck to saying "No items found". But the statictext field shows the correct value when the button is pressed. For instance when I enter "Sa" or "Ma" the statictext field displays "Sa%" and "Ma%" respectively, and should have picked up "Sam Sub" or "Mary Sun", but unfortunately, and amazingly, the table doesn't even flicker for a microsec. JESUS!

Note that a pretty large & complex model webapp that used Derby was also transported from JSC to Tomcat and it worked without absolutely any problems, despite the 39 SQL used being so very complex.

Mary

marysama at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...
# 19

Wow! Pretty odd! You tried using the printstatements property of the rowset? This dumps the sql into the server log. You can then have a look an see if anything dodgy is going on.

Sorry am off to bed now so if this is not solved same time tomorrow will see if i can offer any more suggestions.

yossariana at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...
# 20
I set the printstatement true, in JSC it printed the SQL used, but in Tomcat it did not print in any of its log files. Mary
marysama at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...
# 21

Yahoooooooo!!

Here's a workaround for those who are struggling to deploy JSC webapps using MySql 5.0 in Tomcat 5.5.17. It is one of those Sam's clumsy techniques, but works fine.

(1) Add Sun Server 8.x to Netbeans 5.5

(2) Import JSC web-app to NetBeans (after taking a copy for later JSC use)

(3) Build & test the app in NetBeans

(4) Copy the netbeans created war file to Tomcat

(5) Start Tomcat

(6) As normal use the manager to run the app

(7) As simple and as clumsy as that

Mary

marysama at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...
# 22

In my previous reply I forgot to add the following:

(1) Use MySql Driver 3.1.14 as advised by Yossarian

(2) Use Bilorge's journal to create the context that introduces the datasource and the driver, etc. After which you'll fine the Tomcat's server.xml contain the following sample entry:

<Context

path="/MySqlTest2">

<Resource

auth="Container"

description="Creator generated DataSource Reference"

name="jdbc/MySql1"

type="javax.sql.DataSource"

password="adminadmin"

driverClassName="org.gjt.mm.mysql.Driver"

maxIdle="2"

maxWait="20000"

validationQuery="select * from testtable"

username="root"

url="jdbc:mysql://localhost/Test"

maxActive="4"/>

</Context>

Or cut and paste the above and change the names as per your setup.

marysama at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...
# 23
Marysam,I think I may have run into something similar for a project that I'm doing at work. The difference is that I am working with a MS SQL database and not a MySQL. Can you tell me what the query is for the RowSet object that you are passing the wildcard value to.
bilorgea at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...
# 24
Hi BillyThe table called TestTable contained two columns (code, name). The query was as follows:SELECT code, name FROM TestTable WHERE name LIKE ?Mary
marysama at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...
# 25

If you don't want to make changes in Tomcat, you can also create context.xml inside your project. I noticed NB 5.5 create this file automatically for web project and placed under web/META-INF folder. You can view this in "Files" tab and add contents similar like below to this file. This context file will be packaged into war file and deployed during deployment process

<?xml version="1.0" encoding="UTF-8"?>

<Context path="/exchange">

<Resource driverClassName="com.mysql.jdbc.Driver" maxActive="100" maxIdle="2" maxWait="5000" name="jdbc/testdb" password="dbpassword" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/testdb" username="dbuser"/>

</Context>

WatchBladea at 2007-7-21 15:13:35 > top of Java-index,Development Tools,Java Tools...