You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Scott Purcell <sp...@vertisinc.com> on 2005/04/15 20:24:59 UTC

configure DataSource Question

Hello,
I am trying to configure a javax.sql.DataSource to work with the JDBC pooling stuff.
I have been screwing with this stuff quite a while now and could use some help.

In my Servlet I want to use the JNDI and something like this for a connection:
	Context ctx = new InitialContext();

       DataSource ds =
            (DataSource)ctx.lookup(
               "java:comp/env/jdbc/strutsDB");
        Connection conn = ds.getConnection();


// THIS WORKS, BUT I AM NOT USING THE BasicDataSourceFactory to create the pool.
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="strutsDB" docBase="strutsDB" path="/strutsDB"
  reloadable="true" >
  <Resource name="jdbc/strutsDB" auth="Container" type="javax.sql.DataSource" 
     maxActive="100" maxIdle="30" maxWait="10000" username="javauser" 
     password="javadude" driverClassName="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost:3306/fritest?autoReconnect=true"/>
</Context>



// SO I WANT TO USE THE FOLLOWING, WHICH FAILS WITH THIS ERROR
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of cla
ss '' for connect URL 'null'
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDat
aSource.java:780)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSo
urce.java:540)
        at com.mb.purcell.action.QueryDispatchAction.query(QueryDispatchAction.j
ava:46)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchActio
n.java:280)
        at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:

The below configuration that is causing the failure is basically the same as the above. Why does the above work, and the one I need fails?


I am using this example: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
This is basically the same as above, except for the BasicDataSourceFactory. 

Does anyone know why this does not work? I have struggled too long with this, and could use a hand.

Thanks,
Scott



### context.xml that fails. ###
 

<?xml version='1.0' encoding='utf-8'?>

<Context path="/strutsDB" docBase="strutsDB"
        debug="5" reloadable="true" crossContext="true">

  <Logger className="org.apache.catalina.logger.FileLogger"
             prefix="localhost_FM_log." suffix=".txt"
             timestamp="true"/>

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

  <ResourceParams name="jdbc/strutsDB">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>

    <!-- Maximum number of dB connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to 0 for no limit.
         -->
    <parameter>
      <name>maxActive</name>
      <value>100</value>
    </parameter>

    <!-- Maximum number of idle dB connections to retain in pool.
         Set to 0 for no limit.
         -->
    <parameter>
      <name>maxIdle</name>
      <value>30</value>
    </parameter>

    <!-- Maximum time to wait for a dB connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->
    <parameter>
      <name>maxWait</name>
      <value>10000</value>
    </parameter>

    <!-- MySQL dB username and password for dB connections  -->
    <parameter>
     <name>username</name>
     <value>javauser</value>
    </parameter>
    <parameter>
     <name>password</name>
     <value>javadude</value>
    </parameter>

    <!-- Class name for mm.mysql JDBC driver -->
    <parameter>
       <name>driverClassName</name>
       <value>com.mysql.jdbc.Driver</value>
    </parameter>

    <!-- The JDBC connection url for connecting to your MySQL dB.
         The autoReconnect=true argument to the url makes sure that the
         mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
         connection.  mysqld by default closes idle connections after 8 hours.
         -->
    <parameter>
      <name>url</name>
      <value>jdbc:mysql://localhost:3306/fritest?autoReconnect=true</value>
    </parameter>
  </ResourceParams>
</Context>


Scott K Purcell | Developer | VERTIS |
555 Washington Ave. 4th Floor | St. Louis, MO 63101 |
314.588.0720 Ext:1320 | spurcell@vertisinc.com | http://www.vertisinc.com

Vertis is the premier provider of targeted advertising, media, and 
marketing services that drive consumers to marketers more effectively. 
                                                 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org