Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
-none-

-none-

2007-10-02       - By Heping Ling

 Back
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 (See http://ISO-8859.ora-code.com)-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="jdbc:oracle:thin:@(protected):1521:idm0"

             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(DriverC
onnectionFactory.java:37)

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

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

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

    at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.ja
va: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(Application
FilterChain.java:269)

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

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

    at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va: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(H
ttp11AprProtocol.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


©2008 junlu.com - Jax Systems, LLC, U.S.A.