tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Januski, Ken" <kjanu...@phillynews.com>
Subject Cannot get a DataSource
Date Fri, 20 Aug 2004 21:46:41 GMT
I've been beating my head against the wall on and off for a week now and
just can't seem to get the hand of JNDI DataSources with Tomcat. Everything
I try seems to end with "javax.naming.NamingException: Cannot create
resource instance."

Though I've also done a fair amount of research on this I haven't found any
clear answers as to what exactly causes this error, esp. when using Tomcat.

Thanks for any ideas,

Ken


The entries in server.xml, under <GlobalNamingResources> are:

<Resource name="jdbc/CheckUsers" auth="Container"
type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/CheckUsers">
    	<parameter>
    		<name>driverClassName</name>
    		<value>com.mysql.jdbc.Driver</value>
    	</parameter>
    	<parameter>
    		<name>url</name>
 
<value>jdbc:mysql://inqtomcat/photo?autoReconnect=true</value>
    	</parameter>
    	<parameter>
    		<name>username</name>
    		<value>xxx</value>
    	</parameter>
     	<parameter>
    		<name>password</name>
    		<value>xxx</value>
    	</parameter>
     	<parameter>
    		<name>maxActive</name>
    		<value>10</value>
    	</parameter>
     	<parameter>
    		<name>maxIdle</name>
    		<value>30000</value>
    	</parameter>
     	<parameter>
    		<name>maxWait</name>
    		<value>100</value>
    	</parameter>
     	<parameter>
    		<name>factory</name>
 
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    	</parameter>
    </ResourceParams>
</Resource>

In my web.xml I have:
<resource-ref>
		<res-ref-name>jdbc/CheckUsers</res-ref-name>
		<res-type>javax.sqlDataSource</res-type>
		<res-auth>Container</res-auth>
</resource-ref>

And in the calling code I have:

private DataSource ds;
Context initContext;
Context env;

try {
	initContext = new InitialContext();
	env = (Context)initContext.lookup("java:comp/env");
	ds = (DataSource) env.lookup("jdbc/CheckUsers");
} catch ( NamingException ne ) {
	        logger.info( "Problem setting datasource in setDs using JNDI
and DataSource: " + ne + ".");
} catch ( Exception e ) {
        logger.info( "Problem setting datasource in setDs : " + e + ".");
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message