File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Tomcat 5.0.27 Connection Pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat 5.0.27 Connection Pooling" Watch "Tomcat 5.0.27 Connection Pooling" New topic
Author

Tomcat 5.0.27 Connection Pooling

Kiran Kumar Vasireddy
Greenhorn

Joined: Dec 09, 2009
Posts: 6
Dear All,

I started using tomcat recently and started with version 6 and able develop application . But when I try to deploy it on godaddy shared linux hosting environment ,it has version 5.0.27. Moreover we don't have permission to change server.xml file to implement connection pooling . Could some body please help me in creating connection pooling for MYSQL server on tomcat server 5.0.27 where we don't have access to modify server.xml file( Not sure we can create context.xml on tomcat version 5.0.27 , even we have I think I can not even use context.html on godaddy shared linux hosting environment)

Thanks a lot for your help
Kiran
Misha Ver
Ranch Hand

Joined: Mar 03, 2008
Posts: 470
I would check with GoDaddy about recommended approach. Please check Apache Tomcat Configuration Reference http://tomcat.apache.org/tomcat-5.5-doc/config/context.html about where could you define Context elements

For Tomcat 5, unlike Tomcat 4.x, it is NOT recommended to place <Context> elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat.

Context elements may be explicitly defined: ...
Kiran Kumar Vasireddy
Greenhorn

Joined: Dec 09, 2009
Posts: 6
Thanks for your response . Unfortunately Godaddy is not talking about the connection pooling and they are blindly connecting to the database directly
Please check the their example http://help.godaddy.com/article/3351
I called them several times and but no use.



Regards
Kiran
Misha Ver
Ranch Hand

Joined: Mar 03, 2008
Posts: 470
In this case check the URL that I posted above
Kiran Kumar Vasireddy
Greenhorn

Joined: Dec 09, 2009
Posts: 6
Once again thanks for your response . I used context.xml in version 6 and it worked great , But it is not working for version 5.0 . I think it works only from version 5.5 .Correct me If I am wrong . Moreover in version 6 if I create context.xml file it gets copied automatically to <tomcat home>\conf\Catalina\localhost directory , this is not happening in version 5.0 .

Again godaddy environment context.xml file will not be copied to <tomcat home>\conf\Catalina\localhost even if 5.0 supports because of security reasons.

Regards
Kiran
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

Kiran Kumar Vasireddy wrote:Once again thanks for your response . I used context.xml in version 6 and it worked great , But it is not working for version 5.0 . I think it works only from version 5.5 .Correct me If I am wrong .
Regards
Kiran


You're wrong. The context xml file has been the recommended thing to use (instead of mods to server.xml) since Tomcat 4. I've been using it for years.

Unless someone has done some really bizarre stuff, the same context.xml should work for both Tomcat5 and Tomcat6, and I'm not sure about anything copying it to conf/Catalina/localhost. But then, when I deploy, I normally copy it there myself.

You can also construct a file whose actual name is context.xml and place it in your WAR (check the docs, but I think it goes the the WAR's /META-INF directory). Unless overridden, that context.xml will be used when the app is deployed and you can also define the database connection pool in that file just as in any other context xml file.

Since the conf/Catalina/localhost is a directory that can contain multiple contexts, obviously only one of them could actually be give a name of "context.xml", but in practice, Tomcat just scans for all ".xml" files in that directory and deploys all of them and doesn't care what their actual names are. Perversely, it will also erase files in certain cases when a deployment fails.

In Tomcat4 and (I think) Tomcat5, the context.xml file could also be written to the webapps folder. A problem with that, however, is that if a WAR file and a context file were both copied to that folder, the folder was scanned in alphabetical order, so the war file was seen and processed before (and in place of) the context XML file.

Finally, when doing major redeployments, it's wise to remove all lint. Delete all war files, context files, and exploded war directories related to the app being redeployed from the webapps directory. Especially the exploded WARs, since they'll override unexploded WAR files, even if they're older. Also delete the appropriate directory subtree from the work/Catalina/localhost directory. It's not a bad idea to just delete everything from under the temp directory.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kiran Kumar Vasireddy
Greenhorn

Joined: Dec 09, 2009
Posts: 6
Thanks Tim for your time and for the detailed explanation
I am clear now about context.xml file and trying to use it for the application deployed under root.
I copied context.xml file under ROOT\META-INF and trying to access the application and got the following error

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

I copied the required Driver Jar in all the places ( all the lib folders to make sure for testing) . Could you please let me know what went wrong?

Regards
Kiran

Contents of context.xml file

<Context path="/ROOT" docBase="ROOT" debug="1" reloadable="true">
<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/TestDB">
<parameter>
<name>username</name>
<value>root</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/test</value>
</parameter>
</ResourceParams>
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

That one always annoys me. I think it means you need to copy a mysql driver jar into your Tomcat lib directory. In Tomcat 5, I think it's the shared/lib directory.

Why the classname shows as '' I've never figured out.
Kiran Kumar Vasireddy
Greenhorn

Joined: Dec 09, 2009
Posts: 6
I copied the required Jar in all the LIB folders but still gave the same error . But at last by setting the context path to "" it worked. I mean the first line I changed to

<Context path=""

But this worked only for me when I copied manually context.xml file under conf\Catalina\localhost directory . I am going to create a war file and try to deploy and see what happens .

But again godaddy environment settings are different , not sure what what context I have to give and document root I have to give.

Regards
Kiran
Kiran Kumar Vasireddy
Greenhorn

Joined: Dec 09, 2009
Posts: 6
I am able to deploy with war file in my local environment .
But again on Godaddy environment I am getting the same error.
I am going crazy for last 15 days , but not found a solution . I called godaddy people , but no perfect answer .

I am able to connect to database directly through my JSP or servlet and able to get the result on Godaddy hosting environment. I mean if I hard code the database connection string,userid and password . But if I use context.xml I am getting null pointer exception on the screen . As per the tomcat configuration install doc if you copy context.xml under META-INF/context.xml It will be picked by tomcat and writes it under conf\Catalina\localhost directory with your jar file name . In shared environment I am not getting a away to check this ..

Is there any way to check the file copied properly or not to conf\Catalina\localhost directory?
Or if it doesn't there any other way to implement connection pooling in Godaddy environment?
and surprisingly the logs what they are asking me to check are under stats directory with error_logs directory . But that doesn't contain much information.Are there any other error logs I can check?

Regards
Kiran
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat 5.0.27 Connection Pooling
 
Similar Threads
Recommendations for Webhosting for Struts2 (GoDaddy issue)
Does Spring framework supported by godaddy shared linux hosting
Facelets not working on Godaddy
Java Web Application in Shared Hosting Account