I use JDK1.6 and Tomcat5.5.17,I want to use JNDI in tomcat,so I do like
follows:
Tomcat/conf/context.xml
<Context>
<Resource name="jdbc/test"
 type="javax.sql.DataSource" auth="Container"
 driverClassName="ooracle.jdbc.driver.OracleDriver" maxActive="100"
 maxIdle="30" maxWait="10000"
 url="jdbc:oracle:thin:@localhost:1521:EDWARD"
 username="scott" password="tiger" />
  <!-- Default set of monitored resources -->
   <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

Tomcat/conf/server.xml
......
<!-- Global JNDI resources -->
 <GlobalNamingResources>
   <!-- Test entry for demonstration purposes -->
   <Environment name="simpleValue" type="java.lang.Integer" value="30"/>

   <!-- Editable user database that can also be used by
        UserDatabaseRealm to authenticate users -->
   <Resource name="UserDatabase" auth="Container"
             type="org.apache.catalina.UserDatabase"
      description="User database that can be updated and saved"
          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
         pathname="conf/tomcat-users.xml" />
 </GlobalNamingResources>
......

Tomcat/webapps/myweb/WEB-INF/web.xml
......
<resource-ref>
  <description>Oracle Datasource example</description>
 <res-ref-name>jdbc/test</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>
</web-app>

 I call JNDI in my code,like follows:

 Context initContext = new InitialContext();
  Context envContext  = (Context)initContext.lookup("java:/comp/env");
  DataSource ds = (DataSource)envContext.lookup("jdbc/test");
  Connection conn = ds.getConnection();

But when I run it,it raise following errors:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver
class 'oracle.jdbc.driver.OracleDriver'
       at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(
BasicDataSource.java:766)
       at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(
BasicDataSource.java:540)
       at SKY.manage.loginAction.execute(test.java:35)
       at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(Execute
Action.java:53)
       at org.apache.struts.chain.commands.AbstractExecuteAction.execute(
AbstractExecuteAction.java:64)
       at org.apache.struts.chain.commands.ActionCommandBase.execute(
ActionCommandBase.java:48)
       at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java
:190)
       at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand
java:304)
       at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java
:190)

Why raise above error? Please help.

Thanks

Reply via email to