tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebastião Carlos Santos" <scarlosan...@bol.com.br>
Subject JNDI + Tomcat + Oracle 9i Database
Date Tue, 25 Feb 2003 16:35:20 GMT
I am trying to configure JNDI to access Oracle 9i R1,  
according to JNDI Datasource HOW-TO,  
however I am not obtaining a lot of success when I go  
to establish the connection.

In the end of this e-mail I will list some fragments of the configuration of server.xml,
web.xml and of my class java that I am using to accomplish the connection test.

Files in $CATALINA_HOME/common/lib
root@xxx:/usr/local/jakarta-tomcat-4.1.18/common/lib > ls
activation.jar  commons-collections.jar  commons-pool.jar     jdbc2_0-stdext.jar  mail.jar
           naming-resources.jar
ant.jar         commons-dbcp.jar         jasper-compiler.jar  jndi.jar            naming-common.jar
  ojdbc14.jar
classes12.jar   commons-logging-api.jar  jasper-runtime.jar   jta.jar             naming-factory.jar
 servlet.jar

The reference $CATALINA_HOME/common/lib/*. jar is in CLASSPATH of the system

Fragment of configuration of server.xml

<Host name="aaa.aa.aa" debug="0" appBase="/web"
      unpackWARs="true" autoDeploy="true">

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

        <Context path="" docBase="/web/ged" debug="0"
                 reloadable="true" crossContext="true">

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

          <Ejb   name="ejb/EmplRecord" type="Entity"
                 home="com.wombat.empl.EmployeeRecordHome"
               remote="com.wombat.empl.EmployeeRecord"/>

          <Environment name="maxExemptions" type="java.lang.Integer"
                      value="15"/>

          <Parameter name="context.param.name" value="context.param.value"
                     override="false"/>

          <Resource name="jdbc/EmployeeAppDb" auth="SERVLET"
                    type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/EmployeeAppDb">
            <parameter><name>username</name><value>sa</value></parameter>
            <parameter><name>password</name><value></value></parameter>
            <parameter><name>driverClassName</name>
              <value>org.hsql.jdbcDriver</value></parameter>
            <parameter><name>url</name>
              <value>jdbc:HypersonicSQL:database</value></parameter>
          </ResourceParams>

          <Resource name="jdbc/sged" auth="Container"
                    type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/sged">
            <parameter><name>factory</name>
              <value>org.apache.commons.dbcp.BasicDataSourceFactory</value></parameter>
            <parameter><name>driverClassName</name>
              <value>oracle.jdbc.driver.OracleDriver</value></parameter>
            <parameter><name>url</name>
              <value>jdbc:oracle:thin@xxx.xxx.xx:1521:XXX</value></parameter>
            <parameter><name>username</name><value>scott</value></parameter>
            <parameter><name>password</name><value>jjjjj</value></parameter>
            <parameter><name>maxActive</name><value>20</value></parameter>
            <parameter><name>maxIdle</name><value>10</value></parameter>
            <parameter><name>maxWait</name><value>10000</value></parameter>
            <parameter><name>removeAbandoned</name><value>true</value></parameter>
            <parameter><name>removeAbandonedTimeout</name><value>60</value></parameter>
            <parameter><name>logAbandoned</name><value>true</value></parameter>
          </ResourceParams>

          <Resource name="mail/Session" auth="Container"
                    type="javax.mail.Session"/>
          <ResourceParams name="mail/Session">
            <parameter>
              <name>mail.smtp.host</name>
              <value>localhost</value>
            </parameter>
          </ResourceParams>
          <ResourceLink name="linkToGlobalResource"
                    global="simpleValue"
                    type="java.lang.Integer"/>
        </Context>

      </Host>

File /web/WEB-INF/web.xml

<?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>
    <description>Oracle Database Connection</description>
    <resource-ref>
      <description>Pool</description>
      <res-ref-name>jdbc/sged</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>
    <welcome-file-list>
      <welcome-file>index.html</welcome-file>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>index.htm</welcome-file>
    </welcome-file-list>
  </web-app>


Method of the class java that makes the connection test

public String obtem_dados()
            {
                Connection conn = null;
                Statement stmt = null;
                ResultSet rset = null;
                resultado = new StringBuffer();
                try
                    {
                        Context initContext = new InitialContext();
                        Context envContext = (Context)initContext.lookup("java:/comp/env");
                        DataSource ds = (DataSource)envContext.lookup("jdbc/sged");
                        conn = ds.getConnection();
                        stmt = conn.createStatement();
                        rset = stmt.executeQuery("SELECT COUNT(*) FROM V$SESSION");
                        if (rset.next())
                            {
                                resultado.append("Número de Conexões -> ");
                                resultado.append(rset.getString(1));
                                resultado.append("<br>");
                            }
                    }
                catch (java.lang.Exception e)
                    {
                        resultado.append(e.getMessage());
                        resultado.append("<br>");
                    }
                finally
                    {
                        if (conn != null)
                            {
                                try
                                    {
                                        conn.close();
                                    }
                                catch (java.lang.Exception ex)
                                    {
                                        resultado.append(ex.getMessage());
                                        resultado.append("<br>");
                                    }
                            }
                    }
                return ((resultado.toString()));
            }

Ao executar o método anterior, recebo a seguinte mensagem de erro:

Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL 'jdbc:oracle:thin@ged.ufu.br:1521:GED'

Alguém tem alguma idéia do que pode estar acontecendo?

Excuse me for the gigantic message.  
I thank in advance.
Sebastião Carlos Santos
Oracle Database Administrator 
Universidade Federal de Uberlândia - UFU
Gratificação de Estímulo à Docência - GED


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message