Configuring and using DataSource in Tomcat

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, everybody:

 

I am new in doing web applications and new in using tomcat.  I am having trouble configuring and using DataSource in Tomcat.  Hope someone could see where the problem is.

 

About the database:

    hostname is sb.lehman.cuny.edu

    schema name (sqlplus account name) is devtrack

    listener port is 1521

    Oracle SID is idm0

 

1. J2SE SDK version on my PC: 1.5.0_11

 

2. File name and location of the JDBC driver:

File name: ojdbc14dms.jar. I put it in c:\tomcat\common\lib.  The driver file is copied from the JDeveloper that runs on the same PC as I run Tomcat.  The JDeveloper runs servlets OK on the PC and accesses the same database OK with the 1.5.0_11 J2SE SDK.

3. The web.xml file

At the very beginning of the application's deployment descriptor (c:\tomcat\webapps\myApp\WEB-INF\web.xml), I declared the JNDI reference for the database.  Here is the beginning portion of the web.xml file:

 

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app

  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

  "http://java.sun.com/dtd/web-app_2_3.dtd">

 

<web-app>

<resource-ref>

   <description>

      Resource reference to a factory for java.sql.Connection instances

   </description>

   <res-ref-name>

      jdbc/DBDevTrackConnDS

   </res-ref-name>

   <res-type>

      javax.sql.DataSource

   </res-type>

   <res-auth>

      Container

   </res-auth>

</resource-ref>

 

4. The c:\tomcat\conf\context.xml file

I added the <Resource> element in the context.xml.  The entire file of c:\tomcat\conf\context.xml is as follows:

 

<!-- The contents of this file will be loaded for each web application -->

<Context>

    <!-- Default set of monitored resources -->

    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->

    <!--

    <Manager pathname="" />

    -->

    <Resource name="jdbc/DBDevTrackConnDS"

              auth="Container"

              type="javax.sql.DataSource"

              username="devtrack"

              password="test123"

              driverClassName="oracle.jdbc.driver.OracleDriver"

              url="">

              maxActive="8"

              maxIdle="4" />

</Context>

 

5. The servlet file.

The init() method in the serverlet file (for obtaining a DataSource object):

 

public class LoginServletNew extends HttpServlet {

  PrintWriter out = null;

  DataSource ds = null;

 

  public void init() {

    try {

    Context initCtx = new InitialContext();

    Context envCtx = (Context) initCtx.lookup("java:comp/env");

    ds = (DataSource) envCtx.lookup("jdbc/DBDevTrackConnDS");

    } catch (NamingException e) {

       e.printStackTrace();

    }

  }

 

The login() method that uses the DataSource:

 

  boolean login(String userName, String password) {

    try {

      Connection con = ds.getConnection();

 

      Statement s = con.createStatement();

      String sql = "SELECT LDAP_UID FROM Users" +

         " WHERE LDAP_UID='" + userName + "'" + " AND USER_TYPE='" + password + "'";

      ResultSet rs = s.executeQuery(sql);

      if (rs.next()) {

        out.println("uid from query: " + rs.getString(1));

        rs.close();

        s.close();

        con.close();

        return true;

      }

      rs.close();

      s.close();

      con.close();

    }

 

6. The trouble:

The servlet compiles OK.  It runs OK when the user is presented with the login form.  But when the submit button is clicked that submits the username and password (i.e., the login() method is called), the browser receives an err page with the root cause as NoClassDefFoundError:

root cause

java.lang.NoClassDefFoundError: oracle/dms/instrument/ExecutionContextForJDBC

 

In the localhost.2007-10-02.log file, the root cause stack is as follows:

SEVERE: Servlet.service() for servlet NewLogin threw exception

java.lang.NoClassDefFoundError: oracle/dms/instrument/ExecutionContextForJDBC

     at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:322)

     at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:151)

     at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)

     at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:608)

     at org.apache.tomcat.dbcp.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)

     at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)

     at org.apache.tomcat.dbcp.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)

     at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)

     at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)

     at LoginServletNew.login(LoginServletNew.java:95)

     at LoginServletNew.doPost(LoginServletNew.java:77)

     at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)

     at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)

     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)

     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)

     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)

     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)

     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)

     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)

     at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:834)

     at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)

     at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)

     at java.lang.Thread.run(Unknown Source)

 

 

It seems to me that even though the JDBC driver was found and compilation was OK at compile time, it cannot be found at runtime.  But it is not clear to me what is wrong and how to correct it.  It would be very much appreciated if someone with experienced eye could spot the cause of the error and help me out.

 

 

Jason


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux