tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fawaz Ahmad <fah...@csce.uark.edu>
Subject JNDI help
Date Fri, 04 Oct 2002 21:17:38 GMT
Hello,

Can anyone help me with this problem.  I have read up on Tomcat JNDI from
the Tomcat HowTo webpage and tried to implement it in my
servlet.  Unfortunately, I can not seem to get it to work.  My servlet
works fine when i use the original code to access the database:


      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
      //establish the connection
      Connection conn = DriverManager.getConnection(url,dbUsr, dbPsw);


But when I try using the JNDI service my servlet doesn't seem to access
the database.  I am using the following code.  Is ther something trival
that I might be leaving out?

  Context ctx = (Context) new InitialContext().lookup("java:comp/env");
  Connection conn = ((DataSource) ctx.lookup("jdbc/WebOE")).getConnection();

where my servlet's web.xml is:

<web-app>
    <resource-ref>
      <res-ref-name>jdbc/WebOE</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>

    <servlet>
      <servlet-name>WebOE</servlet-name>
      <servlet-class>WebOE</servlet-class>
      <init-param>
        <param-name>LogPath</param-name>
        <param-value>c:\test\Log</param-value>
      </init-param>
    </servlet>
</web-app>


And my entry to server.xml is:

<Context path="/WebOE" docBase="WebOE" debug="0" reloadable="true"/>

<Resource name="jdbc/WebOE" auth="Container" type="javax.sql.DataSource"/>
  <ResourceParams name="jdbc/WebOE">
   <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <parameter>
      <name>username</name>
      <value>weboe</value>
    </parameter>
    <parameter>
      <name>password</name>
      <value>weboe</value>
    </parameter>
    <parameter>
      <name>driverClassName</name>
      <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
    </parameter>
    <parameter>
      <name>url</name>
      <value>jdbc:microsoft:sqlserver://spacejam:1433;DatabaseName=WebOE</value>
    </parameter>
    <parameter>
      <name>maxActive</name>
      <value>25</value>
    </parameter>
    <parameter>
      <name>maxIdle</name>
      <value>4</value>
    </parameter>
  </ResourceParams>



Fawaz




--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message