This is mistaken, if you mean what you say. There is a JDBC resource available via JNDI in Tomcat. You have to code it, of course, but it definitely is available.

At 02:53 PM 8/15/2003 -0500, Madere, Colin wrote:
I think your inclinations that Tomcat is not a naming service are correct.
I have not seen reference to anything that suggests you can set up resources
in Tomcat that are available via JNDI.  JBoss, certainly, as it does provide
a JNDI server (whatever the appropriate name for that is), as I've used that
with JMS/JBossMQ.  AFAIK, the Tomcat JNDI setup stuff is just for processes
internal to Tomcat, but that is an educated guess, not a known fact :)

-----Original Message-----
From: Jason Mowat [mailto:[EMAIL PROTECTED]
Sent: Friday, August 15, 2003 12:14 PM
To: [EMAIL PROTECTED]
Subject: JNDI References To Tomcat 4.1


Greetings,


I am trying to create a standalone application that references a DBCP on
Tomcat.  I'm not sure if I can do this; I've seem some articles that seem to
suggest that it can be done, but again, I'm not sure.  I've read
http://www.mail-archive.com/[EMAIL PROTECTED]/msg08353.html.

I have set up in tomcat/conf/server.xml the following context info:

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

    <ResourceParams name="jdbc/test_db">
      <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:@internal.sbgh.mb.ca:1521:test</value>

</parameter>

      <parameter>
        <name>username</name>
        <value>test</value>
      </parameter>

      <parameter>
        <name>password</name>
        <value>test</value>
      </parameter>

      <parameter>
        <name>maxActive</name>
        <value>20</value>
      </parameter>

      <parameter>
        <name>maxIdle</name>
        <value>30000</value>
      </parameter>

      <parameter>
        <name>maxWait</name>
        <value>100</value>
      </parameter>
    </ResourceParams>

</DefaultContext>

Note that I have not created any references in a web.xml, since I will not
be running an application, per se, from Tomcat.  PERHAPS THIS IS WHERE MY
PROBLEM IS?

The client code I am using is not a servlet or a JSP; it's a simple piece of
code to see if I can communicate with the database pool on Tomcat as
configured above.

Hashtable env = new Hashtable();
env.put(
        Context.INITIAL_CONTEXT_FACTORY,
        "org.apache.commons.dbcp.BasicDataSourceFactory"
);

//  ***  THIS IS ANOTHER AREA WHERE I MAY BE WRONG! *** env.put(
        Context.PROVIDER_URL,
        "http://localhost:8080";
);

try {
        InitialContext initCtx = new InitialContext(env);
        DataSource ds =
(DataSource)initCtx.lookup("java:comp/env/jdbc/test_db");
        Connection conn = ds.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet rset = stmt.executeQuery("SELECT * FROM tbl_test");
        conn.close();
        initCtx.close();
}
catch(NamingException e) {
        fail("Naming exception thrown");
}
catch (SQLException e) {
        fail("SQL Exception thrown");
}

I start Tomcat, assuming that the pool is set up.  Then I use the client to
try to get an initial context from it.  This throws a naming exception,
because it doesn't know how to get an initial context for
org.apache.commons.dbcp.BasicDataSourceFactory at http://localhost:8080.

My first question: can I do this?
My second question: If I can't do it like this, do I need to set up a JNDI
provider (like on JBoss) and set up the pooling there? My final question:
It "feels" as if my problem is simply setting up the PROVIDER_URL properly
so that it can get the context from Tomcat.  I've done LDAP PROVIDER_URLs
before, but never one that gets a data source factory from a servlet
container.  Can I use http over port 8080 to get the data source factory?
Is there a different mechanism for getting the factory from code that is not
residing within the servlet container?  Can this even be done on Tomcat?

I appreciate any help that anyone can provide.

Cheers,
Jason


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



LEGAL NOTICE


This electronic mail transmission and any accompanying documents contain information belonging to the sender which may be confidential and legally privileged. This information is intended only for the use of the individual or entity to whom this electronic mail transmission was sent as indicated above. If you are not the intended recipient, any disclosure, copying, distribution, or action taken in reliance on the contents of the information contained in this transmission is strictly prohibited. If you have received this transmission in error, please delete the message. Thank you



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to