× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi David,
I'm trying to replace our home written ConnectionPool class to manage JDBC 
connections with the UDBConnectionPoolDataSource as explained by Richard 
Dettinger in his January 2002 article in iSeries magazine. Right now we create 
ConnectionPool in our Login servlet init() method (being called when Tomcat is 
started) and place a reference to that object into ServletContext for future 
reference by every servlet that needs a database connection. We have a static 
class Pool with method getConnection() which performs a lookup for given 
attribute name in a ServletContext for reference to the ConnectionPool object, 
gets connection from the pool and return it to the requester. After use servlet 
calls Pool.freeConnection(Connection con) which returns given connection back 
to the pool.
I want to create UDBConnectionPoolDataSource and use it as a connection factory 
with the statement pooling. The problem that I see is that I have to create 
ConnectionPoolDataSource first and than create standard data source to 
reference it and I don't know how to do this without JNDI as shown in Richard's 
example:
        // Create a ConnectionPoolDataSource implementation
        UDBConnectionPoolDataSource cpds = new UDBConnectionPoolDataSource();
      cpds.setDescription("Connection Pooling DataSource object with Statement 
pooling");
      cpds.setMaxStatements(10);

      // Establish a JNDI context and bind the connection pool data source
      Context ctx = new InitialContext();
      ctx.rebind("StatementSupport", cpds);


      // Now create a standard datasource that references it.
      UDBDataSource ds = new UDBDataSource();
      ds.setDescription("DataSource supporting statement pooling");
      ds.setDataSourceName("StatementSupport");
      ctx.rebind("StatementPoolingDataSource", ds);

I don't want to use JNDI because it is an expensive operation but it seems the 
only way how to reference one type of object to another... Maybe you can help 
me to figure-out this?
By the way - after proper tuning (as you recommended) I got Tomcat4.1.12 
working fine, thanks...

Alex Pinsky
Intranet developer
Aeropostale, Inc.

-----Original Message-----
From: David Morris [mailto:David.Morris@plumcreek.com]
Sent: Friday, December 13, 2002 2:04 PM
To: java400-l@midrange.com
Subject: Re: JNDI on AS400


What are you sharing this connection with? Using JNDI is great
if you have two components that don't know about each other,
but there is a lot of overhead involved. You might consider
creating your own cache for connections and putting a reference
to them into a static locator. You can wrap that around your
initial context if necessary to give you the best of both worlds.
If I were to guess, I would say in your second example you used
the wrong name in your lookup.

David Morris

>>> apinsky@aeropostale.com 12/13/02 10:30AM >>>
This is a multi-part message in MIME format.
--
--
[ Picked text/plain from multipart/alternative ]
Hi,
I'm trying to configure Tomcat to use UDBDConnectionPoolDataSource as
statement pooled connection factory and can't get JNDI to work.
Before run it under Tomcat I want to make sure that JNDI portion of the
code would work. The code is:




import java.sql.*;
import javax.naming.*;
import java.util.*;
import com.ibm.db2.jdbc.app.UDBDataSource;


public class UDBDataSourceExample1
{
    public static void main(java.lang.String[] args)
    throws Exception
    {
        UDBDataSource ds = new UDBDataSource();
        ds.setDescription("Basic DataSource");
        System.out.println("dataSource created");


        Context ctx = new InitialContext();


        ctx.rebind("BaseDataSource", ds);
    }
}

Error message when trying to rebind:
javax.naming.NoInitialContextException:
Need to specify class name in environment or system property, or as an
applet parameter, or in an application resource file:
java.naming.factory.initial
....

and if I'm running the same code with initial context set as:

import java.sql.*;
import javax.naming.*;
import java.util.*;
import com.ibm.db2.jdbc.app.UDBDataSource;
public class UDBDataSourceExample1
{
    public static void main(java.lang.String[] args)
    throws Exception
    {
        UDBDataSource ds = new UDBDataSource();
        ds.setDescription("Basic DataSource");
        System.out.println("dataSource created");
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.sun.jndi.fscontext.RefFSContextFactory");
        env.put(Context.PROVIDER_URL, "file:/jdbc/DataSources");
        System.out.println("envelope created");

        // Establish a JNDI context.
        Context ctx = new InitialContext(env);
        System.out.println("Context created");
        ctx.rebind("BaseDataSource", ds);
    }
}
javax.naming.NameNotFoundException; remaining name
'"/jdbc/DataSources"'
      java/lang/Throwable.<init>()V+4 (Throwable.java:78)
      java/lang/Exception.<init>()V+1 (Exception.java:29)
      javax/naming/NamingException.<init>()V+1
(NamingException.java:112)
      javax/naming/NameNotFoundException.<init>()V+1
(NameNotFoundException.java 44...

We are running V5R1 with all latest PTF installed and I run second
example with fscontext.jar included in class path
_______________________________________________
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) 
mailing list
To post a message email: JAVA400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/java400-l
or email: JAVA400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.