Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Tomcat DataSource config issue

Thread view: 
MileHighCelt - 19 Dec 2005 21:38 GMT
I have been searching and searching for the answer to this, and despite
seeing many similar questions, I have yet to find the answer.  I have a
struts 1.1 application using Tomcat 4.x that I will eventually move to
Tomcat 5.0.    I have the mysql-connector-java-3.1.10-bin.jar, the 4
commons jar files in /$CATALINA_HOME/common/lib.

When I try to lookup the DataSource I get the following error:

org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver
of class '' for connect URL 'null', cause:
java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:243)
... etc...

Here is the serverl.xml:
<Resource name="jdbc/jsidb" auth="Container"
type="javax.sql.DataSource"
              maxActive="100" maxIdle="30" maxWait="10000"
              username="user" password="password"
driverClassName="com.mysql.jdbc.Driver"

url="jdbc:mysql://127.0.0.1:3306/jsi_db?autoReconnect=true"/>

Here is the web.xml
 <resource-ref>
     <description>DB Connection</description>
     <res-ref-name>jdbc/jsidb</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
 </resource-ref>

And finally the code that is trying to get a Connection:
InitialContext initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/jsidb");

I do not understand why this is so complicated, it seems pretty
straightforward - but I have already spent two days trying a variety of
combinations and still I cannot get the DataSource to work.

I really, really appreciate any help you can offer.
Tim Terry - 19 Dec 2005 23:25 GMT
> I have been searching and searching for the answer to this, and despite
> seeing many similar questions, I have yet to find the answer.  I have a
[quoted text clipped - 37 lines]
>
> I really, really appreciate any help you can offer.

I had a similar problem with 5.5 and solved it by setting the factory
class name in the resource and adding the resource to my webapp's
context xml (not server xml) file inside
$TOMCAT_HOME/conf/Catalina/localhost:

<Resource name="jdbc/db_name" auth="Container" type="javax.sql.DataSource"
        maxActive="5" maxIdle="2" maxWait="10000" username="user"
        password="password" driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://127.0.0.1:3306/Users?autoReconnect=true"
        removeAbandoned="true"
        removeAbandonedTimeout="60"
        factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"/>

however the datasource factory in 5.0 is different to 5.5, i think its:
org.apache.commons.dbcp.BasicDataSourceFactory. I'm not sure if the
factory classname is important.

Hope that helps

Tim
Daniel Rohe - 20 Dec 2005 09:15 GMT
MileHighCelt schrieb:
> I have been searching and searching for the answer to this, and despite
> seeing many similar questions, I have yet to find the answer.  I have a
[quoted text clipped - 18 lines]
>
> url="jdbc:mysql://127.0.0.1:3306/jsi_db?autoReconnect=true"/>

You know that resource configuration has changed in Tomcat 5.5 and this
seems to be a configuration for Tomcat 5.5 and not for Tomcat 4.1 or
5.0! Look at [1] for a Tomcat 4.1 DataSource configuration.

[1]
http://tomcat.apache.org/tomcat-4.1-doc/jndi-datasource-examples-howto.html

Kind regards,
Daniel
MileHighCelt - 28 Dec 2005 15:29 GMT
Thank you, I hadn't realized there was a big difference.  What I am
wondering is that because I am deploying to Tomcat/webapps/ROOT is it
perhaps the context being messed up?  I didn't declare a <context>
around my datasource in the server.xml because that was throwing
errors.  Do you think that could cause a problem?
MileHighCelt - 13 Jan 2006 15:35 GMT
Just a follow up for those that are searching for the answer to this.
In my case, because I was deploying to the ROOT context, I didn't have
a <context> declaration, which actually works fine until you need the
JNDI lookup.  So, I just created an appropriate <context>
<resourceparams></resourceparams></context></host>  that worked.

Hope that helps.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.