tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roberts, Eric" <Eric.Robe...@one.at>
Subject RE: DBCP question
Date Thu, 05 Dec 2002 09:29:19 GMT
Hi Veniamin,

Try this way instead - it works for me!

Server.xml:
<Resource description="Oracle database resource for esljsp project" 
name="jdbc/esljsp-oracle" 
auth="Container" 
type="javax.sql.DataSource"/>
.
.
<ResourceParams name="jdbc/esljsp-oracle">
.
.
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@db.server.ru:1521:sidvalue</value>
</parameter>.
.

web.xml:
.
.
  <resource-ref>
   <description>Oracle database resource for esljsp project</description>
   <res-ref-name>jdbc/esljsp-oracle</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
  </resource-ref>
.
.

Source:
.
.
import javax.naming.Context;
import javax.naming.InitialContext;
.
.
    ctx = new InitialContext();
    Context envCtx = (Context) ctx.lookup("java:/comp/env/");
    DataSource ds = (DataSource) envCtx.lookup("/esljsp-oracle");

Hope this helps!

-----Original Message-----
From: Veniamin Fichin [mailto:3ca28f66@mail.ru]
Sent: Mittwoch, 04. Dezember 2002 20:28
To: Tomcat Users List
Subject: DBCP question


Hello cats!

I'm trying to implement connection pool with Oracle8 database. After 
some codewriting I stuck with a problem which I don't know how to solve. 
Here are my configs and source code.

--= [ server.xml ] =--
<Server port="8005" shutdown="SHUTDOWN" debug="0">
  <Service name="Tomcat-Standalone">
   <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
              port="8080"
              minProcessors="5"
              maxProcessors="75"
              enableLookups="true"
              acceptCount="10"
              debug="0"
              connectionTimeout="20000"
              useURIValidationHack="false" />
   <Engine name="Standalone" defaultHost="localhost" debug="0">
    <Logger className="org.apache.catalina.logger.FileLogger"
            prefix="catalina_log." suffix=".txt"
            timestamp="true" />
    <Host name="localhost"
          debug="0"
          appBase="webapps"
          unpackWARs="true" autoDeploy="true">
     <Logger className="org.apache.catalina.logger.FileLogger"
             directory="logs"  prefix="localhost_log." suffix=".txt"
             timestamp="true" />
     <Context path="/esljsp" docBase="esljsp" debug="5"
              reloadable="true">
<!-- I suspect I've chosen wrong class in "type" value -->
      <Resource name="jdbc/esljsp-oracle"
                type="oracle.jdbc.pool.OracleConnectionPoolDataSource"
                auth="Container"
                description="Oracle database resource for esljsp project" />
      <ResourceParams name="jdbc/esljsp-oracle">
       <parameter>
        <name>dataSourceName</name>
        <value>oracle.jdbc.pool.OracleDataSource</value>
       </parameter>
       <parameter>
        <name>description</name>
        <value>Oracle database resource for esljsp project</value>
       </parameter>
       <parameter>
        <name>serverName</name>
        <value>db.server.ru</value>
       </parameter>
       <parameter>
        <name>portNumber</name>
        <value>1521</value>
       </parameter>
       <parameter>
        <name>networkProtocol</name>
        <value>tcp</value>
       </parameter>
       <parameter>
        <name>databaseName</name>
        <value>sidvalue</value>
       </parameter>
       <parameter>
        <name>user</name>
        <value>username</value>
       </parameter>
       <parameter>
        <name>password</name>
        <value>password</value>
       </parameter>
      </ResourceParams>
      <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="localhost_esljsp_log." suffix=".txt"
              timestamp="true" />
     </Context>
    </Host>
   </Engine>
  </Service>
</Server>
--= [ / server.xml ] =--

--= [ / 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>
<!--
  <taglib>
   <taglib-uri>/esl-adm.tld</taglib-uri>
   <taglib-location>/WEB-INF/esl-adm.tld</taglib-location>
  </taglib>
-->
  <servlet>
   <servlet-name>DBAccessTest</servlet-name>
   <servlet-class>ru.rbcsoft.esljsp.DBAccessTest</servlet-class>
  </servlet>
  <servlet-mapping>
<!-- this servler creates OracleConnectionPoolDataSource instance right -->
   <servlet-name>DBAccessTest</servlet-name>
   <url-pattern>/dbaccess/DBAccessTest</url-pattern>
  </servlet-mapping>
  <resource-ref>
   <description>Oracle database resource for esljsp project</description>
   <res-ref-name>jdbc/esljsp-oracle</res-ref-name>
   <res-type>oracle.jdbc.pool.OracleConnectionPoolDataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Unshareable</res-sharing-scope>
  </resource-ref>
</web-app>
--= [ / web.xml ] =--

--= [ index.jsp ] =--
<%@ page isThreadSafe="false" info="Database access test|Index page"
          contentType="text/html; charset=utf-8" %>
<%@ page import="javax.naming.InitialContext, javax.naming.Context" %>
<%@ page import="oracle.jdbc.pool.OracleConnectionPoolDataSource" %>
<html>
  <head>
   <title>Database access test: index page</title>
  </head>
  <body>
<%
Context ctx=new InitialContext();
OracleConnectionPoolDataSource oracpds=
 
(OracleConnectionPoolDataSource)ctx.lookup("java:comp/env/jdbc/esljsp-oracle");
out.print(oracpds);
%>
  </body>
</html>
--= [ index.jsp ] =--

And I get this error:

javax.servlet.ServletException: Cannot create resource instance

But DBAccessTest servlet, mentioned above, cat instantiate 
OracleConnectionPoolDataSource.

As I understand, there is at leave to way to implement dbcp -- Tomcat 
way (org.apache.commons.dbcp.BasicDataSourceFactory) and Oracle way, and 
I've chosen wrong one. But I still want it to be done with Oracle 
implementation.
If there are any solid reasons that Tomcat way is better (except of 
interportability), I would love to hear them all!


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message