tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Cummings" <je...@ltis.net>
Subject MSQL and JDNI
Date Tue, 08 Jul 2003 20:24:30 GMT
I am try to setup a JDNI datasource. This is the exerp from my context. I
store app context in $CATILINA_HOME/webapp/myapp.xml file
<Context path="/jtest"

docBase="C:\myapp"

crossContext="false"
                                                            debug="9"

reloadable="true">
                                                            <Logger
className="org.apache.catalina.logger.FileLogger"

prefix="localhost_myapp_log." suffix=".txt"

timestamp="true"/>
                                                            <ResourceLink
name="linkToGlobalResource" global="simpleValue"

type="java.lang.Integer"/>

                                                   <Resource
name="mail/Session" auth="Container"

type="javax.mail.Session"/>
                                                            <ResourceParams
name="mail/Session">

<parameter>

<name>mail.smtp.host</name>

<value>localhost</value>

</parameter>

</ResourceParams>
                                                            <Resource
name="jdbc/MSQL" auth="Container"

type="java.sql.DataSource"/>

                                                            <ResourceParams
name="jdbc/MSQL">
                                                                <parameter>

<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
                                                                </parameter>
                                    <!-- MSQL dB username and password for
dB connections  -->

<parameter>

<name>username</name>

<value>uname</value>

</parameter>

<parameter>

<name>password</name>

<value>pword</value>

</parameter>

                                    <!-- Class name for msql JDBC driver -->

<parameter>

<name>driverClassName</name>

<value>com.ashna.jturbo.driver.Driver</value>

</parameter>

                                    <!-- The JDBC connection url for
connecting to your MSQL dB.                                    -->

<parameter>

<name>url</name>

<value>jdbc:JTurbo://MYSERVER:1036/mydatabase</value>

</parameter>

</ResourceParams>
</Context>

I also added the following to web.xml for this app
<resource-ref>
                   <description>DB Connection</description>
                   <res-ref-name>jdbc/MSQL</res-ref-name>
                   <res-type>javax.sql.DataSource</res-type>
                   <res-auth>Container</res-auth>
               </resource-ref>

My servlet fails – dataSource is null. Here is the code
try {
                                    Context init = new InitialContext();
                                    Context ctx = (Context)
init.lookup("java:comp/env");
                                    DataSource dataSource = (DataSource)
ctx.lookup("jdbc/MSQL");

                        }
        catch (NamingException ex) {
                                    throw new ServletException("Cannot
retrieve java:comp/env/jdbc/conversion",ex);
        }

Any ideas?????

Jeff



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