You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Robert Dana <rd...@macroint.com> on 2000/12/05 16:41:01 UTC

mod_jk and JDBC?

I am trying to upgrade from Tomcat 3.1 and mod_jserv to Tomcat 3.2 and mod_jk. 
Everything seemed to go just fine with the installation, and I am able to run
JSPs and servlets without any problems.  With one BIG exception: the upgrade has
left me without the capacity to establish JDBC connections.  The details of my
environment are as follows:

RedHat Linux 6.2
Apache 1.3.9
mod_jk built from the Jakarta-tomcat-3.2-src distribution
Oracle 8.0.5

To illustrate the problem, I wrote a simple servlet to test if JDBC works.  I
also wrote this as a Java program, which runs from the command line without a
problem.  I know, therefore, that my database is responding normally to JDBC
calls.  As a servlet, however, the program reports that the driver is loaded and
then throws an SQLException indicating that it cannot connect to the database
server.  When Tomcat starts up, it does report that the JDBC drivers are in its
CLASSPATH and, as I said, the driver does get loaded OK, it just can't connect. 


By the way, just to keep things as simple as possible, Apache, Tomcat and Oracle
are all running on the same machine in this example.  The servlet also runs fine
under Tomcat 3.1 and mod_jserv.

Has anyone else experienced this problem?  Can anybody suggest a solution?

Robert Dana
ORC Macro International


import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class ReadFromCarmen extends HttpServlet
{
   public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException
  {
       res.setContentType("text/html");
       PrintWriter out = res.getWriter();

       // The driver to load
       String driver_class = "oracle.jdbc.driver.OracleDriver";

       // The query we will execute
       String query = "select sysdate from dual";

       try
       {
            // Load the JDBC driver
            Class.forName(driver_class);

            out.println("loaded...<BR>");         // servlet works up to this
point

            // Connect to the database
            // !! actual server name has been removed just for this email !!
            Connection conn = DriverManager.getConnection
                ("jdbc:oracle:thin:@xxxx:1521:ora8",
                 "scott", "tiger");

            out.println("connected...<BR>");   // this never makes it to the
browser

            // Create a statement
            Statement stmt = conn.createStatement();

            out.println("created statement...<BR>");

            // Execute the query
            ResultSet rset = stmt.executeQuery(query);

            out.println("executed query...<BR>");

            // Dump the result
            while (rset.next ())

            out.println(rset.getString(1));

      }
      catch (ClassNotFoundException e)
      {
            out.println("Trouble loading JDBC driver...\n" + e.getMessage());
      }
      catch (SQLException e)
      {
            out.println("SQL Trouble...\n " + e.getMessage());
      }
  }
}


*******************************************************************
This e-mail and any attached files are confidential.  If you feel you have received the transmission in error, please immediately notify the system  manager at ORC Macro, at e-mail postmaster@macroint.com or by  phone at (301)572-0911.  The entire contents of this transmission were  scanned during the sending process using McAfee Anti-Virus software.  Macro assumes no responsibility or liability for undetected viruses.  All  recipients are encouraged to further scan the message/files with their  product of choice prior to use.  Any viruses detected should be reported  as noted above.  Thank you.