You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Justin Schoeman <ju...@expertron.co.za> on 2006/02/24 20:11:33 UTC

JNDI connection pooling in axis2?

OK, after numerous hacks, my software is functioning! Now I just need to 
cache the DB connections and I am home free ;-).

Unfortunately, as usual, this is giving me more problems than expected.

So far, I have done the following:

added:

<resource-ref>
  <description>Oracle Datasource example</description>
  <res-ref-name>jdbc/grinpal</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

inside the <web-app> token in 
/usr/share/tomcat5/webapps/axis2/WEB-INF/web.xml

added a context file /usr/share/tomcat5/webapps/axis2/META-INF/context.xml:

<?xml version='1.0' encoding='utf-8'?>
<Context path="/axis2" debug="5" reloadable="true" 
docBase='${catalina.home}/server/webapps/axis2'>

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

     <ResourceParams name="jdbc/grinpal">
       <parameter>
          <name>factory</name>
          <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
       </parameter>
       <parameter>
          <name>driverClassName</name>
          <value>oracle.jdbc.driver.OracleDriver</value>
       </parameter>
       <parameter>
          <name>url</name>
          <value>jdbc:oracle:thin:@//172.xxx.xxx.xxx:1521/orcl</value>
       </parameter>
       <parameter>
          <name>username</name>
          <value>XXXXXXX</value>
       </parameter>
       <parameter>
         <name>password</name>
         <value>XXXXXX</value>
       </parameter>
       <parameter>
         <name>maxActive</name>
         <value>20</value>
       </parameter>
       <parameter>
         <name>maxIdle</name>
         <value>10</value>
       </parameter>
       <parameter>
         <name>maxWait</name>
         <value>-1</value>
       </parameter>
     </ResourceParams>

</Context>

And added the code:

System.out.println("connecting to db");
javax.naming.Context initContext =
	new javax.naming.InitialContext();
System.out.println("got init");
javax.naming.Context envContext =
	(javax.naming.Context)initContext.lookup("java:/comp/env");
System.out.println("got env");
javax.sql.DataSource ds =
	(javax.sql.DataSource)envContext.lookup("jdbc/grinpal");
System.out.println("got ds");
Connection conn = ds.getConnection();
System.out.println("connected to db");
stmt = dbConn.createStatement();
res = stmt.executeQuery("select switch_address, title, initials, 
surname, street_number, street_name from customer where card_nr="+cardNr);


to my webservice.  In theory, this should work, but I get:
connecting to db
got init
got env
got ds
Error querying customer db: org.apache.commons.dbcp.SQLNestedException: 
Cannot create JDBC driver of class '' for connect URL 'null'



Obviously, it is not retrieving the parameters correctly... I tried 
moving context.xml out, and this results in the same error. So it seems 
my context.xml is not being loaded, or is incorrect. Anybody have any ideas?

Thanks,

Justin

SOLVED! Re: JNDI connection pooling in axis2?

Posted by Justin Schoeman <ju...@expertron.co.za>.
Should have read the docs (or at least the right version of the docs). 
To get this working, simply add to

/usr/share/tomcat5/conf/server.xml

After the closing </Host> tag for localhost:

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

  <ResourceParams name="jdbc/grinpal">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <parameter>
      <name>driverClassName</name>
      <value>oracle.jdbc.driver.OracleDriver</value>
    </parameter>
    <parameter>
      <name>url</name>
      <value>jdbc:oracle:thin:@//172.27.0.12:1521/orcl</value>
    </parameter>
    <parameter>
      <name>username</name>
       <value>ppdev</value>
    </parameter>
    <parameter>
      <name>password</name>
      <value>waterloo</value>
    </parameter>
    <parameter>
      <name>maxActive</name>
      <value>20</value>
    </parameter>
    <parameter>
      <name>maxIdle</name>
      <value>10</value>
    </parameter>
    <parameter>
      <name>maxWait</name>
      <value>-1</value>
    </parameter>
  </ResourceParams>

</Context>


AND added:

  <resource-ref>
   <description>Oracle Datasource example</description>
   <res-ref-name>jdbc/grinpal</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
  </resource-ref>

  inside the <web-app> token in
  /usr/share/tomcat5/webapps/axis2/WEB-INF/web.xml

-justin

Justin Schoeman wrote:
> OK, after numerous hacks, my software is functioning! Now I just need to 
> cache the DB connections and I am home free ;-).
> 
> Unfortunately, as usual, this is giving me more problems than expected.
> 
> So far, I have done the following:
>