aspose file tools*
The moose likes Tomcat and the fly likes Can't get connection from DataSource object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Can Watch "Can New topic
Author

Can't get connection from DataSource object

Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
I am having trouble setting up connection pooling on a linux server using mysql and tomcat 6

I have created a context.xml and put it in my deployed application WEB-INF directory


My web.xml



My application code



And finally the exception.



I searched other similar posts but could not find problem. Any suggestions are greatly appreciated.

Thanks
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

I had same problem recently.

check in $TOMCAT_HOME/conf/Catalina/localhost

for a file called $appname.xml
where $appname is your web application name.
This file is a copy of your context.xml from when you first deployed. If you fixed context.xml since your first deployment, the changes won't be reflected in $appname.xml. Your app is still trying to read from it, however. You can edit $appname.xml by hand or delete it.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168


org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'Apr 5, 2010 4:32:35 PM org.apache.catalina.core.ApplicationContext log
INFO: StudentServlet: SQLException caught Cannot create JDBC driver of class '' for connect URL 'null'


Wow, this is I think the third post I have seen this week about this issue! We weren't able to figure out the issue in the other two threads. Tim's suggestion here does make sense.



[My Blog] [JavaRanch Journal]
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9521
    
    2

Tim McGuire wrote:I had same problem recently.

check in $TOMCAT_HOME/conf/Catalina/localhost

for a file called $appname.xml
where $appname is your web application name.
This file is a copy of your context.xml from when you first deployed. If you fixed context.xml since your first deployment, the changes won't be reflected in $appname.xml. Your app is still trying to read from it, however. You can edit $appname.xml by hand or delete it.


Even I have the same problem with DBCP Tomcat Connection Pooling. I'm using Oracle 10g and Tomcat 5.5.28 and JDK 1.4.

I tried to look for the file ($MyProject.xml) in the location you specified. But I'm not finding any such file! I just see that there are two files (host-manager.xml and manager.xml).

Is there really a solution to this problem???
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

"No Suitable Driver" means that your driver class wasn't found in Tomcat's classpath. You've either misspelled the classname or you need to place a copy of the jar that contains the driver in $TOMCAT_HOME/lib.

The reason you haven't found a copy of the context in the $TOMCAT_HOME/Catalina/localhost directory is because you supplied it as file "META-INF/context.xml" in your WAR. Tomcat has no need to make a copy of it.


Customer surveys are for companies who didn't pay proper attention to begin with.
Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
Tim Holloway wrote:"No Suitable Driver" means that your driver class wasn't found in Tomcat's classpath. You've either misspelled the classname or you need to place a copy of the jar that contains the driver in $TOMCAT_HOME/lib.


I have verified that the jar does exists in the tomcat lib directory. I actually have this working w/o connection pooling using the same driver so I do not think that the driver not being their is the issue. Is their a setting in the server.xml where you need to turn connection pooling on? Tomcat has all the info it needs to create connections but do you have to tell tomcat to do it?

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

The only thing you need is the datasource resource definition itself. There are not additional switches to turn on. Although, as one of your fellow-sufferers has least, XML is case-sensitive.

Very definitely however, "No Suitable Driver" means that the driver class could not be resolved. Which means that a Class.forName("com.mysql.jdbc.Driver") done in the connection pool failed to find the class. Since I'm pretty sure you capitalized the driverClassName attribute properly (which is the third way this could fail), I'd recommend doing a "jar tvf $TOMCAT_HOME/lib/xxxxxx.jar" (replaces "x"s with your mysql driver jar filename) and verifying that the resulting output has a com.mysql.jdbc.Driver.class in it.
Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
result from jar tvf command on mysql jar file in tomcat home lib directory

692 Wed Mar 05 17:26:52 EST 2008 com/mysql/jdbc/Driver.class
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Fabio Piergentili wrote:result from jar tvf command on mysql jar file in tomcat home lib directory

692 Wed Mar 05 17:26:52 EST 2008 com/mysql/jdbc/Driver.class


Just want to confirm that when you say "tomcat home lib" you are not talking about

$TOMCAT_HOME/lib

it should be in
$TOMCAT_HOME/common/lib
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Tim McGuire wrote:
Fabio Piergentili wrote:result from jar tvf command on mysql jar file in tomcat home lib directory

692 Wed Mar 05 17:26:52 EST 2008 com/mysql/jdbc/Driver.class


Just want to confirm that when you say "tomcat home lib" you are not talking about

$TOMCAT_HOME/lib

it should be in
$TOMCAT_HOME/common/lib


Not for Tomcat6. The unholy trinity of Tomcat libraries went away after tomcat 5.x. Now there's only TOMCAT_HOME/lib.

Technically, I think it's actually $CATALINA_BASE/lib, but I can never keep CATALINA_BASE and CATALINA_HOME straight unless I go back and reference the docs. I don't run enough instances where the two have differing values.
Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
created a common/lib directory and put it in their just to test for bug but no luck. Still same error.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Tim Holloway wrote:

Not for Tomcat6. The unholy trinity of Tomcat libraries went away after tomcat 5.x. Now there's only TOMCAT_HOME/lib.



I'll be damned. I did not realize that.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Tomcat won't even see your common/lib. Even if you explicitly add it to the classpath, it's not likely to find it, since Tomcat maintains its own internal set of classpaths.

For Tomcat6 JDBC driver jars should be placed in TOMCAT_HOME/lib. I guarantee they'll be found there. So far I've done that for MySQL, PostgreSQL, DB2 and Oracle, and in quite a few cases, I've had multiple database vendor's jars in there at the same time.
Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
I am a bit confused. You first said to put in common. I did that just to test if their was a bug. The mysql jar is in $TOMCAT_HOME/lib. I still get that error. If it is finding it then what could be the problem? Is it a bug? Is it the url? Since we verified that the driver class is their and in the correct place. I just do not know what to do next.....

Thanks for trying all...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

I didn't say common/lib. That was the other Tim. common/lib, server/lib and whatever the third lib directory was (I forget) were features of earlier releases of Tomcat. They were replaced by TOMCAT_HOME/lib in Tomcat6.

There is no magic there.


This will give me access to class com.mysql.jdbc.driver. Assuming I've made a proper MYSQL JDBC URL so that this driver will claim it, that's all there is.
Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
I have verified all that. I did the jar thing and I do have the driver in the correct place. In addition, I know tomcat can find it as I can connect to the DB without pooling via



I know their is no magic but it seems I have everything in place but it doesn't work. You mentioned the url. I did try different ways( w and wo password etc..)
I just do not know what to try next.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

I'd try removing the "?autoreconnect=" part of the URL. For one thing, I think that's a Connection Pool attribute, so the Connection Pool URL parser may be mangling what you provided. Some people have suggested using 127.0.0.1 instead of localhost, but I don't think that's actually necessary.

I do talk to MySQL connection pools all the time with (relatively) little grief. It might help if you got a co-worker to look at this stuff. A lot of times when I'm having problems that nothing seems to solve it turns out I've developed a blind spot to something fairly simple.
Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
Ok thanks for all your help. I will post back if I figure out something.
Misha Ver
Ranch Hand

Joined: Mar 03, 2008
Posts: 470
Fabio Piergentili wrote:
I have created a context.xml and put it in my deployed application WEB-INF directory


I see the misprint in the line 2. Is this a real code?
Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
I wish that was it....but it was just a typo in the post....thanks

Fabio
Fabio Piergentili
Ranch Hand

Joined: Sep 04, 2009
Posts: 57
As Tim mentioned on a previous post I developed a blind spot and that spot was that I put the context.xml file under WEB-INF and not META-INF in the war file. It was not seeing it at all. Also for tomcat6 do not put
factory="org.apache.commons.dbcp.BasicDataSourceFactory entry in context.xml. Lastly, tomcat copies the context.xml from your war to $CATALINA_HOME/conf/Catalina/[host]/[renamedToApplicationContextPath.xml. I had to manually delete it for the new one to take effect.

Thanks all for your help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't get connection from DataSource object