tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eichfelder, Frank" <Frank.Eichfel...@t-systems.com>
Subject AW: Problem with Oracle/JNDI/DataSource
Date Wed, 17 Apr 2002 12:24:22 GMT
Hi Laura,

databaseName is the SID.
The default port is 1521.

I actually have found how to make the setting in the server.xml-file:

<Resource name="jdbc/BuergerPortalDb" auth="Container"
                  type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/BuergerPortalDb">
            <parameter><name>factory</name><value>oracle.jdbc.pool.OracleDataSourceFactory</value></parameter>
            <parameter><name>url</name><value>jdbc:oracle:thin:username/password@host:port:sid</value></parameter>
          </ResourceParams>

Now, you have to add, as described earlier, this entry to your web.xml-file:

<resource-ref>
    <description>DataSource</description>
    <res-ref-name>jdbc/BuergerPortalDb</res-ref-name>
    <res-type>oracle.jdbc.pool.OracleConnectionPoolDataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
  </resource-ref>

As <res-type> you can also set oracle.jdbc.pool.OracleDataSource, if you don't want
to use the ConnectionPool-class.

Now, you can get a connection in your program via the following lines:

	Context initCtx = new InitialContext();

      Context envCtx = (Context) initCtx.lookup("java:comp/env");

      ConnectionPoolDataSource cpds = (ConnectionPoolDataSource) envCtx.lookup("jdbc/BuergerPortalDb");
      PooledConnection pconn = cpds.getPooledConnection();
	Connection conn = pconn.getConnection();

If you don't use the ConnectionPool-class, it's even easier:
	Context initCtx = new InitialContext();

      Context envCtx = (Context) initCtx.lookup("java:comp/env");

      DataSource ds = (DataSource) envCtx.lookup("jdbc/BuergerPortalDb");
	Connection conn = ds.getConnection();


I hope this information is complete enough... I tested it with Tomcat 4.0.3 and always got
a connection. If you are interested in the server.xml-settings for Cloudscape-databases or
MySQL-databases, then feel free to contact me.

Tanti saluti,

Frank



> -----Urspr√ľngliche Nachricht-----
> Von: Laura [mailto:lauradiara@libero.it]
> Gesendet am: Mittwoch, 17. April 2002 12:44
> An: Tomcat Users List; Eichfelder, Frank
> Betreff: Re: Problem with Oracle/JNDI/DataSource
> 
> Hi Frank,
> 
> I have a question:  I use Oracle 8.1.6 and JNDI DataSource 
> (Re: AW: PLEASE 
> HELP ME: JNDI ERROR 1) gives me an error.
> I can try to use your  method, but I have a question.
> 
> Where is the SID of the DB?
> What is databaseName?
> Is the port the default 1521?
> 
> Thanks
> 
> 
> Laura
> 
> 
> 
> Alle 14:54, martedì 16 aprile 2002, Eichfelder, Frank ha scritto:
> > Hi,
> >
> > I finally managed to get the JNDI-DataSource to work with 
> Tomcat 4.0.3.
> > Here the setting of server.xml:
> >
> > <Resource name="jdbc/BuergerPortalDb" auth="Container"
> >                   type="javax.sql.DataSource"/>
> >           <ResourceParams name="jdbc/BuergerPortalDb">
> >            
> > 
> <parameter><name>factory</name><value>oracle.jdbc.pool.OracleD
> ataSourceFact
> >ory</value></parameter>
> > <parameter><name>user</name><value>xxx</value></parameter>
> > <parameter><name>password</name><value>xxx</value></parameter>
> > <parameter><name>driverType</name><value>thin</value></parameter>
> > <parameter><name>serverName</name><value>server</value></parameter>
> > <parameter><name>portNumber</name><value>port</value></parameter>
> > 
> <parameter><name>databaseName</name><value>dbName</value></parameter>
> > </ResourceParams>
> >
> > Now, I added the following in my web.xml:
> >
> > <resource-ref>
> >     <description>description</description>
> >     <res-ref-name>jdbc/BuergerPortalDb</res-ref-name>
> >     
> <res-type>oracle.jdbc.pool.OracleConnectionPoolDataSource</res-type>
> >     <res-auth>Container</res-auth>
> >     <res-sharing-scope>Shareable</res-sharing-scope>
> >   </resource-ref>
> >
> > And finally, in the Java-File I added:
> >
> > 	Context initCtx = new InitialContext();
> >
> >       Context envCtx = (Context) initCtx.lookup("java:comp/env");
> >       ConnectionPoolDataSource cpds = (ConnectionPoolDataSource)
> > envCtx.lookup("jdbc/BuergerPortalDb");
> >
> >       PooledConnection pconn = 
> cpds.getPooledConnection("xxx", "xxx");
> >
> >       Connection conn = pconn.getConnection();
> >
> > And, you won't believe it, it really works!!!
> >
> > But there's one odd point I want to correct:
> > The User/Password-Setting in the server.xml file is always 
> ignored - I have
> > always to pass these two parameters when calling
> > getPooledConnection("name", "password");
> >
> > If I call getPooledConnection() without these two 
> parameters, I get some
> > nice exceptions.
> >
> > Now it is quite tedious to store the 
> user/password-combination in the
> > source-code, if you could store it in the server.xml...
> >
> > Has anybody an idea how to make it work via server.xml only?
> >
> > Frank
> 
> --
> To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
> Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>
> 

--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message