Link to home
Start Free TrialLog in
Avatar of LeanMoreTryMore
LeanMoreTryMore

asked on

simple JSP page not recognize the Database.java class - Failed to connect to the Oracle database

I have modified the server.xml and created a simple JSP page for testing database connection but I got the following error.
Please advise and correct my mistake

Error
=============================================================================
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 2 in the jsp file: /DBTest.jsp    <=======* Failed to recognize the Database.java **
Generated servlet error:
Syntax error on token "Invalid Character", delete this token

An error occurred at line: 2 in the jsp file: /DBTest.jsp
Generated servlet error:
Syntax error on token "Invalid Character", delete this token

An error occurred at line: 2 in the jsp file: /DBTest.jsp
Generated servlet error:
Syntax error on token "Invalid Character", delete this token

An error occurred at line: 2 in the jsp file: /DBTest.jsp
Generated servlet error:
Syntax error on token "Invalid Character", delete this token

An error occurred at line: 2 in the jsp file: /DBTest.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens


      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)

=============================================================================

DBTest.jsp
===========================================================================
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*, AAPL.*" errorPage="" %>
<%  Database db = new Database();
    db.makeConnection();  
    Connection con = db.getConnection();  
    Statement stmt = con.createStatement();  
    ResultSet rs = stmt.executeQuery("SELECT employee_no, task_desc FROM em_queue");    
    if (rs !=null) {
       while (rs.next()) {
         String EmployeeNo = rs.getString("employee_no");
         String TaskDesc = rs.getString("task_desc");
       }
    }
%>

==============================================================================
server.xml
=======

<!-- Example Server Configuration File -->
<Server port="8005" shutdown="SHUTDOWN">

  <!-- Comment these entries out to disable JMX MBeans support used for the
       administration web application -->
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>

  <!-- 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>
  <!-- Define the Tomcat Stand-Alone Service -->
  <Service name="Catalina">
    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector
               port="8090" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
    <!-- Note : To disable connection timeouts, set connectionTimeout value to 0 -->
      
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009"   enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />


    <!-- Define the top level container in our container hierarchy -->
    <Engine name="Catalina" defaultHost="localhost">

<Context path="/AAPL" docBase="AAPL"
        debug="5" reloadable="true" crossContext="true">

  <Logger className="org.apache.catalina.logger.FileLogger"
        prefix="localhost_DBTest_log." suffix=".txt"
        timestamp="true"/>

  <Resource name="jdbc/myoracle"
               auth="Container"
               type="javax.sql.DataSource"/>

  <ResourceParams name="jdbc/myoracle">

    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>


    <!-- Class name for mm.mysql JDBC driver -->
    <parameter>
       <name>driverClassName</name>
       <value>oracle.jdbc.OracleDriver</value>
    </parameter>


    <parameter>
      <name>url</name>
      <value>jdbc:oracle:thin:guidev@137.172.40.107:1521:gdev</value>
    </parameter>


    <!-- MySQL dB username and password for dB connections  -->
    <parameter>
     <name>username</name>
     <value>guidev</value>
    </parameter>

    <parameter>
     <name>password</name>
     <value>guidev</value>
    </parameter>



    <!-- Maximum number of dB connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to 0 for no limit.
         -->
    <parameter>
      <name>maxActive</name>
      <value>0</value>
    </parameter>

    <parameter>
       <name>removeAbandoned</name>
       <value>true</value>
    </parameter>


    <!-- Maximum number of idle dB connections to retain in pool.
         Set to 0 for no limit.
         -->
    <parameter>
      <name>maxIdle</name>
      <value>0</value>
    </parameter>

    <!-- Maximum time to wait for a dB connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->
    <parameter>
      <name>maxWait</name>
      <value>10000</value>
    </parameter>

    <parameter>
      <name>logAbandoned</name>
      <value>true</value>
    </parameter>

  </ResourceParams>
</Context>


      <!-- This Realm uses the UserDatabase configured in the global JNDI
           resources under the key "UserDatabase".  Any edits
           that are performed against this UserDatabase are immediately
           available for use by the Realm.  -->
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <!-- Comment out the old realm but leave here for now in case we
           need to go back quickly -->
      <!--
      <Realm className="org.apache.catalina.realm.MemoryRealm" />
      -->

      <!-- Replace the above Realm with one of the following to get a Realm
           stored in a database and accessed via JDBC -->

      <!--
      <Realm  className="org.apache.catalina.realm.JDBCRealm"
             driverName="oracle.jdbc.driver.OracleDriver"
          connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
         connectionName="scott" connectionPassword="tiger"
              userTable="users" userNameCol="user_name" userCredCol="user_pass"
          userRoleTable="user_roles" roleNameCol="role_name" />
      -->

      <!--
      <Realm  className="org.apache.catalina.realm.JDBCRealm"
             driverName="sun.jdbc.odbc.JdbcOdbcDriver"
          connectionURL="jdbc:odbc:CATALINA"
              userTable="users" userNameCol="user_name" userCredCol="user_pass"
          userRoleTable="user_roles" roleNameCol="role_name" />
      -->

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

        <!--
        <Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
                 managerClassName="org.apache.catalina.cluster.session.DeltaManager"
                 expireSessionsOnShutdown="false"
                 useDirtyFlag="true"
                 notifyListenersOnReplication="true">

            <Membership
                className="org.apache.catalina.cluster.mcast.McastService"
                mcastAddr="228.0.0.4"
                mcastPort="45564"
                mcastFrequency="500"
                mcastDropTime="3000"/>

            <Receiver
                className="org.apache.catalina.cluster.tcp.ReplicationListener"
                tcpListenAddress="auto"
                tcpListenPort="4001"
                tcpSelectorTimeout="100"
                tcpThreadCount="6"/>

            <Sender
                className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
                replicationMode="pooled"
                ackTimeout="15000"/>

            <Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
                   filter=".*\.gif;.*\.js;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"/>
                   
            <Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
                      tempDir="/tmp/war-temp/"
                      deployDir="/tmp/war-deploy/"
                      watchDir="/tmp/war-listen/"
                      watchEnabled="false"/>
        </Cluster>
        -->        
      </Host>
    </Engine>
  </Service>
</Server>

==============================================================================

Database.Java
=========
package AAPL;
import java.sql.*;
import oracle.jdbc.driver.OracleDriver;

public class Database
{
 Connection con;
 
  public Database()
 {
 }
 
public void makeConnection() throws Exception
 {
   DriverManager.registerDriver(new OracleDriver());
   con = DriverManager.getConnection("jdbc:oracle:thin:@137.172.40.107:gdev", "guidev", "guidev");
 }

 public void closeConnection() throws SQLException
 {
  this.con.close();
 }  

 public Connection getConnection()
 {
   return(this.con);
 }
}


==========================================================================
structure of the Web Appl

Tomcat HOME
   webapps
       AAPL          -- DBTest.jsp  page here
          css
          image
          WEB-INF
              classes
                 AAPL   --  Database.class here



===
Please help as I've already spend more than 5 hours still not working it out the problem
Avatar of Mick Barry
Mick Barry
Flag of Australia image

don't think its not recognising your Database class, looks more like theres a crappy character in there somewhere.
Avatar of LeanMoreTryMore
LeanMoreTryMore

ASKER

as indicated at line 2 I can't see any crappy character as you can see below, except it calls Database()

<%  Database db = new Database();
try deleteing and retyping the line.
or even trying to load it with *just* the first line and see if that runs.
if so add a line at a time to pinpoint the problem.
You are right. Getting better BUT

When I re-type the whole lot and change the first line like below
<%@ page contentType="text/html;charset=windows-1252"  language="java" import="java.sql.*" import="AAPL.*"%>

nOTES: i have seperated two for import java.sql and AAPL

I also got the compilation warning but it lets me run
Compilation Error stating that
Warning(1,1): package name AAPL does not match source file name C:\JDeveloper10g\jdev\mywork\WebServerAAPL\View\src\Database.java



AND run it again but I got different error like below:

500 Internal Server Error
java.sql.SQLException: Io exception: Invalid connection string format, a valid format is: "host:port:sid"       at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:137)      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:174)      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:286)      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:321)      at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)      at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:149)      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:31)      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:551)      at java.sql.DriverManager.getConnection(DriverManager.java:512)      at java.sql.DriverManager.getConnection(DriverManager.java:171)      at Database.makeConnection(Database.java:15)


I think the java program Database IS CORRECT
========
package AAPL;
import java.sql.*;
import oracle.jdbc.driver.OracleDriver;

public class Database
{
 Connection con;
 
  public Database()
 {
 }
 
public void makeConnection() throws Exception
 {
   DriverManager.registerDriver(new OracleDriver());
   con = DriverManager.getConnection("jdbc:oracle:thin:@137.172.40.107:gdev", "guidev", "guidev");
 }

 public void closeConnection() throws SQLException
 {
  this.con.close();
 }  

 public Connection getConnection()
 {
   return(this.con);
 }
}
> con = DriverManager.getConnection("jdbc:oracle:thin:@137.172.40.107:gdev", "guidev", "guidev");

your missing the port, should be "host:port:sid"


Thanks objects

I have changed to

package AAPL;
import java.sql.*;
import oracle.jdbc.driver.OracleDriver;

public class Database
{
 Connection con;
 
  public Database()
 {
 }
 
public void makeConnection() throws Exception
 {
       String dbConn = "jdbc:oracle:thin:guidev/guidev@137.172.40.107:1521:gdev";
       DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
       Connection conn;
       conn = DriverManager.getConnection (dbConn);
       //con = DriverManager.getConnection("jdbc:oracle:thin:@137.172.40.107:1521:gdev", "guidev", "guidev");
 }

 public void closeConnection() throws SQLException
 {
  this.con.close();
 }  

 public Connection getConnection()
 {
   return(this.con);
 }
}


===
But I got compliation error stating that
Error(5,8): duplicate definition of class AAPL.Database

I dont get the above error before I changed. Please advise

> C:\JDeveloper10g\jdev\mywork\WebServerAAPL\View\src\Database.java

noticed that the .java should be in an AAPL directory to match the package
this may be creating the problem.
Thanks object,
Both the sample.jsp page and Database.java works well inside the JDeveloper10g.

But
When I copy
the DBTest.jsp to $TOMCAT_HOME\webapps\AAPL
and
the Database.class to $TOMCAT_HOME\webapps\AAPL\WEB-INF\classes

I got the following error
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 2 in the jsp file: /DBTest.jsp
Generated servlet error:
Database cannot be resolved or is not a type

An error occurred at line: 2 in the jsp file: /DBTest.jsp
Generated servlet error:
Database cannot be resolved or is not a type

      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)

==================================================================

I think DBTest.jsp can't find the Database.class

Please advise
> the Database.class to $TOMCAT_HOME\webapps\AAPL\WEB-INF\classes

Database.class should be in:

$TOMCAT_HOME\webapps\AAPL\WEB-INF\classes\AAPL

(because it is in the AAPL package)
Sorry object, forgot to mention this. Yesterday once I received your advise, I try to remove the package in the Database.java. To make it easy,

//package AAPL;
import java.sql.*;
import oracle.jdbc.driver.OracleDriver;
public class Database
{
 Connection con;
 
  public Database()
 {
 }
 
public void makeConnection() throws Exception
 {
   DriverManager.registerDriver(new OracleDriver());
    System.out.println("before Inside make connection");
   con = DriverManager.getConnection("jdbc:oracle:thin:@137.172.40.107:1521:gdev", "guidev", "guidev");
   System.out.println("Inside make connection");
 }

 public void closeConnection() throws SQLException
 {
  this.con.close();
 }  

 public Connection getConnection()
 {
   return(this.con);
 }
}


DBTest.jsp
=======
<%@ page contentType="text/html;charset=windows-1252"  language="java" import="java.sql.*" %>
<%
    Database db = new Database();
    db.makeConnection();
    Connection con = db.getConnection();
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT to_char(sysdate,'dd/mm/yyyy') today FROM dual");
    if (rs !=null) {
       while (rs.next()) {
         String EmployeeNo = rs.getString("today");
       }  
    }      
%>

In the first line, I just import java.sql.*, because the database resides in the current folder, i run the DBTest page, it works inside the JDeveloper10g
tomact requires packages, it won't find classin the default package
does that mean i need to make it as a jar file
I make a Database.jar file and copy to $TOMCAT_HOME/webapps/AAPL

Do i need to change the server.xml and web.xml files?
> does that mean i need to make it as a jar file

not necessary

> Do i need to change the server.xml and web.xml files?

If they reference the Database class then you need to use the correct (fully qualified) class name
YOu said , "they reference the Database class then you need to use the correct (fully qualified) class name"

Does "THEY" mean the JSP pages?

yes. DBTest is referencing the Database.class to be used to connect the database.


server.xml
=======

<!-- Example Server Configuration File -->
<Server port="8005" shutdown="SHUTDOWN">

  <!-- Comment these entries out to disable JMX MBeans support used for the
       administration web application -->
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>

  <!-- 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>
  <!-- Define the Tomcat Stand-Alone Service -->
  <Service name="Catalina">
    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector
               port="8090" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
    <!-- Note : To disable connection timeouts, set connectionTimeout value to 0 -->
     
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009"   enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />


    <!-- Define the top level container in our container hierarchy -->
    <Engine name="Catalina" defaultHost="localhost">

<Context path="/AAPL" docBase="AAPL"                               <************** Change here, isn't it ****>
        debug="5" reloadable="true" crossContext="true">

  <Logger className="org.apache.catalina.logger.FileLogger"
        prefix="localhost_DBTest_log." suffix=".txt"
        timestamp="true"/>

  <Resource name="jdbc/myoracle"
               auth="Container"
               type="javax.sql.DataSource"/>

  <ResourceParams name="jdbc/myoracle">

    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>


    <!-- Class name for mm.mysql JDBC driver -->
    <parameter>
       <name>driverClassName</name>
       <value>oracle.jdbc.OracleDriver</value>
    </parameter>


    <parameter>
      <name>url</name>
      <value>jdbc:oracle:thin:guidev@137.172.40.107:1521:gdev</value>
    </parameter>


    <!-- MySQL dB username and password for dB connections  -->
    <parameter>
     <name>username</name>
     <value>guidev</value>
    </parameter>

    <parameter>
     <name>password</name>
     <value>guidev</value>
    </parameter>



    <!-- Maximum number of dB connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to 0 for no limit.
         -->
    <parameter>
      <name>maxActive</name>
      <value>0</value>
    </parameter>

    <parameter>
       <name>removeAbandoned</name>
       <value>true</value>
    </parameter>


    <!-- Maximum number of idle dB connections to retain in pool.
         Set to 0 for no limit.
         -->
    <parameter>
      <name>maxIdle</name>
      <value>0</value>
    </parameter>

    <!-- Maximum time to wait for a dB connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->
    <parameter>
      <name>maxWait</name>
      <value>10000</value>
    </parameter>

    <parameter>
      <name>logAbandoned</name>
      <value>true</value>
    </parameter>

  </ResourceParams>
</Context>


      <!-- This Realm uses the UserDatabase configured in the global JNDI
           resources under the key "UserDatabase".  Any edits
           that are performed against this UserDatabase are immediately
           available for use by the Realm.  -->
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <!-- Comment out the old realm but leave here for now in case we
           need to go back quickly -->
      <!--
      <Realm className="org.apache.catalina.realm.MemoryRealm" />
      -->

      <!-- Replace the above Realm with one of the following to get a Realm
           stored in a database and accessed via JDBC -->

      <!--
      <Realm  className="org.apache.catalina.realm.JDBCRealm"
             driverName="oracle.jdbc.driver.OracleDriver"
          connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
         connectionName="scott" connectionPassword="tiger"
              userTable="users" userNameCol="user_name" userCredCol="user_pass"
          userRoleTable="user_roles" roleNameCol="role_name" />
      -->

      <!--
      <Realm  className="org.apache.catalina.realm.JDBCRealm"
             driverName="sun.jdbc.odbc.JdbcOdbcDriver"
          connectionURL="jdbc:odbc:CATALINA"
              userTable="users" userNameCol="user_name" userCredCol="user_pass"
          userRoleTable="user_roles" roleNameCol="role_name" />
      -->

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

        <!--
        <Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
                 managerClassName="org.apache.catalina.cluster.session.DeltaManager"
                 expireSessionsOnShutdown="false"
                 useDirtyFlag="true"
                 notifyListenersOnReplication="true">

            <Membership
                className="org.apache.catalina.cluster.mcast.McastService"
                mcastAddr="228.0.0.4"
                mcastPort="45564"
                mcastFrequency="500"
                mcastDropTime="3000"/>

            <Receiver
                className="org.apache.catalina.cluster.tcp.ReplicationListener"
                tcpListenAddress="auto"
                tcpListenPort="4001"
                tcpSelectorTimeout="100"
                tcpThreadCount="6"/>

            <Sender
                className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
                replicationMode="pooled"
                ackTimeout="15000"/>

            <Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
                   filter=".*\.gif;.*\.js;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"/>
                   
            <Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
                      tempDir="/tmp/war-temp/"
                      deployDir="/tmp/war-deploy/"
                      watchDir="/tmp/war-listen/"
                      watchEnabled="false"/>
        </Cluster>
        -->        
      </Host>
    </Engine>
  </Service>
</Server>

===========================================================================
Tomcat is so difficult to understand
> Does "THEY" mean the JSP pages?

No I meant your xml config, but I can't see where Database class is mentioned anywhere in there.
Do I need to specify in server.xml file? I didnt put in here.
it does not make any sense to me. let's say if i have hundred java class files, this means i have to add hundred entries to the server.xml. I have spent alot of time reading tomcat, they dont say that.

But all the information I found from different web sites including EE, only cover Tomcat V3, or V4. I use Tomcat latest version 5.5, this is very different.

Do you have Tomcat 5.5 installed on your pc? if yes, how do u set up to connect the database. I think it needs to set up in the JNDI.. If I dont work out Apache Tomcat I have to report to our manager. The reason I thought it is good to start using Tomcat is free.

I thought i only have to specify the webdoc path like below, it will pick up all the class file under $TOMCAT_HOME/webappl/AAPL

<Context path="/AAPL" docBase="AAPL"                               <************** Change here, isn't it ****>
        debug="5" reloadable="true" crossContext="true">


> Do I need to specify in server.xml file?

no

I only mentioned it because you asked earlier

Your problem just related to your jsp file and the class file.

Have you put the package declaration back in?
sorry i dont understand the package declaration. I thought i need to convert to jar file instead of class file. Actually I have read the Tomcat's document, I think they do mention to use jar file instead of class file.

How do i make the package declaration?
you had it declared in a package previusly.
you need to add a package statement to the top of the source

it will work as a class file or a jar
I have added the package to the Database.java
package AAPL;


in DBTest.jsp - when i run insde the Jdeveloper i failed to find Database.class. Would you tell me how to change the first line like below to import the Database.class. I try import="/AAPL" but not working.

<%@ page contentType="text/html;charset=windows-1252"  language="java" import="java.sql.*" %>
The way you had it previously

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*, AAPL.*" errorPage="" %>
The JSP program did get compiled but i got another error. Please advise

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: oracle/jdbc/driver/OracleDriver
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
      org.apache.jsp.DBTest_jsp._jspService(org.apache.jsp.DBTest_jsp:66)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NoClassDefFoundError: oracle/jdbc/driver/OracleDriver

It cannot find the oracle jdbc driver classes
It was finding them earlier I think, what did you change?
I follow your advice.

The earlier problem is the JSP page didnt get compiled. Now I think the page did get compiled and executed but it failed because the Oracle jdbc driver file not found. See below codes

Database.java
=========

package AAPL;
import java.sql.*;
import oracle.jdbc.driver.OracleDriver;

public class Database
{
 Connection con;
 
  public Database()
 {
 }
 
public void makeConnection() throws Exception
 {
   DriverManager.registerDriver(new OracleDriver());
    System.out.println("before Inside make connection");
   con = DriverManager.getConnection("jdbc:oracle:thin:@137.172.40.107:1521:gdev", "guidev", "guidev");
   System.out.println("Inside make connection");
 }

 public void closeConnection() throws SQLException
 {
  this.con.close();
 }  

 public Connection getConnection()
 {
   return(this.con);
 }
}



DBTest.jsp
=======
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*, AAPL.*" errorPage="" %>
<P>
  <%
    Database db = new Database();
    db.makeConnection();
    Connection con = db.getConnection();
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT to_char(sysdate,'dd/mm/yyyy') today FROM dual");
    if (rs !=null) {
       while (rs.next()) {
         String EmployeeNo = rs.getString("today");
       }  
    }      
%>
</P>This is used to test DBTest.jsp

====
What I changed was

 import="java.sql.*, AAPL.*"  at line 1
one of your earlier stack traces indicates that at that point it was finding the driver ok:

at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:551)    
at java.sql.DriverManager.getConnection(DriverManager.java:512)    
at java.sql.DriverManager.getConnection(DriverManager.java:171)    
at Database.makeConnection(Database.java:15)

You can download the driver at:

http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
it works. before I close.
Object, would you please tell me how to i see the strack traces in java program and jsp?

In java, i use
ie.printStackTrace()

But i dont know where to see the Stack Trace.

In JSP, where do i find the Stack Trace.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial