You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Chaughtai, Atif (NHLBI)" <Ch...@NHLBI.NIH.GOV> on 2002/07/24 20:12:17 UTC
JNDI Setup Question: Cannot create resource instance
Hello,
> I am having problem setting up JNDI resources with Tomcat 4.0.4 .
> I am using MS SQL Server. I have read and followed the howTo tutorial but
> i keep on getting this exception:
>
> javax.naming.NamingException: Cannot create resource instance
> at
> org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceF
> actory.java:167)
> at
> javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:3
> 11)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:835)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
> at
> gov.nih.nhlbi.training.servlet.DisplayMechanism.handleRequest(Display
> Mechanism.java:44)
>
> My server.xml has following entry:
> <Context path="/training" docBase="training" debug="0"
> reloadable="true" crossContext="true">
> <!-- JNDI SETUP -->
>
> <Resource name="jdbc/SQLServer" auth="Container"
> type="javax.sql.DataSource"/>
>
> <ResourceParams name="jdbc/SQLServer">
> <parameter>
> <name>factory</name>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> </parameter>
> <parameter>
> <name>driverClassName</name>
> <value>com.inet.tds.TdsDriver</value>
> </parameter>
> <parameter>
> <name>url</name>
> <value>jdbc:inetdae7: testdatabase.somemachine.com
> ?database=training</value>
> </parameter>
> <parameter>
> <name>username</name>
> <value> username </value>
> </parameter>
> <parameter>
> <name>password</name>
> <value> password </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>
>
>
> Application web.xml has following entry:
> <!--JNDI SETUP -->
> <resource-ref>
> <description>SQLServer Datasource example</description>
> <res-ref-name>jdbc/SQLServer</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
>
>
> And finally this is java code i am using to get the datasource
>
> javax.naming.Context initContext = new InitialContext();
> javax.naming.Context envContext =
> (javax.naming.Context)initContext.lookup("java:comp/env");
>
> DataSource ds =
> (DataSource)envContext.lookup("jdbc/SQLServer");
> Connection connection = ds.getConnection();
>
> Do you see anything wrong with all this? Any help will be appreciated.
> Thanks in advance.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: JNDI Setup Question: Cannot create resource instance
Posted by Andrew Conrad <an...@msn.com>.
You have some spaces in your parameters that I would remove.
Specifically, your url value, username value, and password value.
I'm not familiar with the TdsDriver, but shouldn't you be specifying the
port to connect to (port 1433 typically).
I used the Microsoft JDBC Driver, (available here:
http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.as
p?url=/MSDN-FILES/027/001/779/msdncompositedoc.xml )
and my resource looks like this:
(NOTE: you may need a factory parameter. In 4.1.x, the default is the
DBCP package. I don't know about your version)
<!-- JNDI SETUP -->
<Resource name="jdbc/DataStorage" scope="Shareable"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/DataStorage">
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://localhost:1433</value>
</parameter>
<parameter>
<name>validationQuery</name>
<value>select * from organizations</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>username</name>
<value>xxx</value>
</parameter>
<parameter>
<name>password</name>
<value>xxx</value>
</parameter>
</ResourceParams>
<!-- end JNDI Setup -->
> -----Original Message-----
> From: Chaughtai, Atif (NHLBI) [mailto:ChaughtA@NHLBI.NIH.GOV]
> Sent: Wednesday, July 24, 2002 2:12 PM
> To: 'tomcat-user@jakarta.apache.org'
> Subject: JNDI Setup Question: Cannot create resource instance
>
>
> Hello,
> > I am having problem setting up JNDI resources with
> Tomcat 4.0.4 .
> > I am using MS SQL Server. I have read and followed the
> howTo tutorial
> > but i keep on getting this exception:
> >
> > javax.naming.NamingException: Cannot create resource instance
> > at
> >
> org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceF
> > actory.java:167)
> > at
> >
> javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:3
> > 11)
> > at
> org.apache.naming.NamingContext.lookup(NamingContext.java:835)
> > at
> org.apache.naming.NamingContext.lookup(NamingContext.java:181)
> > at
> org.apache.naming.NamingContext.lookup(NamingContext.java:822)
> > at
> org.apache.naming.NamingContext.lookup(NamingContext.java:194)
> > at
> >
> gov.nih.nhlbi.training.servlet.DisplayMechanism.handleRequest(Display
> > Mechanism.java:44)
> >
> > My server.xml has following entry:
> > <Context path="/training" docBase="training" debug="0"
> > reloadable="true" crossContext="true">
> > <!-- JNDI SETUP -->
> >
> > <Resource name="jdbc/SQLServer" auth="Container"
> > type="javax.sql.DataSource"/>
> >
> > <ResourceParams name="jdbc/SQLServer">
> > <parameter>
> > <name>factory</name>
> >
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> > </parameter>
> > <parameter>
> > <name>driverClassName</name>
> > <value>com.inet.tds.TdsDriver</value>
> > </parameter>
> > <parameter>
> > <name>url</name>
> > <value>jdbc:inetdae7: testdatabase.somemachine.com
> > ?database=training</value>
> > </parameter>
> > <parameter>
> > <name>username</name>
> > <value> username </value>
> > </parameter>
> > <parameter>
> > <name>password</name>
> > <value> password </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>
> >
> >
> > Application web.xml has following entry:
> > <!--JNDI SETUP -->
> > <resource-ref>
> > <description>SQLServer Datasource example</description>
> > <res-ref-name>jdbc/SQLServer</res-ref-name>
> > <res-type>javax.sql.DataSource</res-type>
> > <res-auth>Container</res-auth>
> > </resource-ref>
> >
> >
> > And finally this is java code i am using to get the datasource
> >
> > javax.naming.Context initContext = new InitialContext();
> > javax.naming.Context envContext =
> > (javax.naming.Context)initContext.lookup("java:comp/env");
> >
> > DataSource ds =
> > (DataSource)envContext.lookup("jdbc/SQLServer");
> > Connection connection = ds.getConnection();
> >
> > Do you see anything wrong with all this? Any help will be
> appreciated.
> > Thanks in advance.
>
> --
> To unsubscribe, e-mail:
> <mailto:tomcat-user-> unsubscribe@jakarta.apache.org>
> For
> additional commands,
> e-mail: <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>