Could it be because of the conflict between the declaration of the resource
as being "shareable" in the server.xml file and being Container in the
web.xml?

I am very new to this stuff.

Andoni.


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Friday, March 21, 2003 3:01 PM
Subject: JNDI problems


>      Hello all.  I have been using Tomcat 4.x, and it's worked very well.
> I had a data source defined in struts, and that worked very well.  Then I
> had a need to access a database from a non-JSP class, so I figured I'd use
> JNDI.  Oddly enough I got this to work the first time.  Then I went to
> tweak it, and now it does not work at all.
>
>      Here is my server.xml settings:
> <Context
>                 className="org.apache.catalina.core.StandardContext"
>                 cachingAllowed="true"
>
charsetMapperClass="org.apache.catalina.util.CharsetMapper"
>                 cookies="true"
>                 crossContext="false"
>                 debug="5"
>                 docBase="/var/tomcat4/webapps/performanceServer"
>                 mapperClass
> ="org.apache.catalina.core.StandardContextMapper"
>                 path="/performanceServer"
>                 privileged="false"
>                 reloadable="false"
>                 swallowOutput="false"
>                 useNaming="true"
>                 wrapperClass="org.apache.catalina.core.StandardWrapper">
>      <Resource
>           auth="SERVLET"
>           description="Performance Server database."
>           name="jdbc/PerformanceDatabase"
>           scope="Shareable"
>           type="javax.sql.DataSource"/>
>      <ResourceParams name="jdbc/PerformanceDatabase">
>           <parameter>
>                <name>driverClassName</name>
>                <value>org.postgresql.Driver</value>
>           </parameter>
>           <parameter>
>                <name>factory</name>
>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>           </parameter>
>           <parameter>
>                <name>maxActive</name>
>                <value>100</value>
>           </parameter>
>           <parameter>
>                <name>maxIdle</name>
>                <value>2</value>
>           </parameter>
>           <parameter>
>                <name>maxWait</name>
>                <value>5000</value>
>           </parameter>
>           <parameter>
>                <name>password</name>
>                <value></value>
>           </parameter>
>           <parameter>
>                <name>url</name>
>                <value>jdbc:postgresql:performance</value>
>           </parameter>
>           <parameter>
>                <name>username</name>
>                <value>perfserver</value>
>           </parameter>
>           <parameter>
>                <name>validationQuery</name>
>                <value></value>
>           </parameter>
>      </ResourceParams>
> </Context>
>
>
> Here is my web.xml entry:
> <!-- JNDI Datasource -->
> <resource-ref>
>      <description>DB Connection</description>
>      <res-ref-name>jdbc/PerformanceDatabase</res-ref-name>
>      <res-type>javax.sql.DataSource</res-type>
>      <res-auth>Container</res-auth>
> </resource-ref>
>
>
> Here is my code to get a connection:
> private static Connection getConnection(){
>      Connection connection = null;
>      try {
>           Context ctx = new InitialContext();
>           if (ctx == null )
>                throw new Exception("Boom - No Context");
>           System.out.println("%%%% getting data source");
>
>           Context environmentContext = (Context)ctx.lookup
> ("java:comp/env");
>           DataSource ds = (DataSource)environmentContext.lookup
> ("jdbc/PerformanceDatabase");
>
>           System.out.println("%%%% got datasource");
>
>           if (ds != null) {
>                System.out.println(ds);
>                connection = ds.getConnection();
>           }
>      System.out.println("%%%% got connection");
>      } catch (Exception e) {
>           e.printStackTrace();
>      }
>      return connection;
> }
>
>
>      The sys.out 'got datasource' prints, but it never gets to 'got
> connection', and no exceptions are thrown.  It just hangs.  There is no
CPU
> useage, so this leads me to think that there is some blocking going on.
> Perhaps the getConnection just isn't able to do something, I just don't
> know what.
>
>      Any ideas?  Thanks!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to