SOLUTION: Sybase jConnect JNDI Driver/Pool Problem

SOLUTION: Sybase jConnect JNDI Driver/Pool Problem

Post by Gordon McKinn » Wed, 16 Jul 2003 01:53:08



jConnect drivers (5.x and probably below) have a problem where by
their JNDI initialisation (through your app server's XML deployment
descriptor) fails to work correctly.

Some of the affected parameters are:
        CHARSET
        CHARSET_CONVERTER_CLASS
        JCONNECT_VERSION

There are more but the source I have provided can be easily extended.

You'll need to use two wrapper classes, one for the pool driver and
one for the factory.

Maybe Sybase could see their way to updating the base classes to
include all properties.

__________________________________________________________________________________________________

import com.sybase.jdbc2.jdbc.SybConnectionPoolDataSource;
import com.sybase.jdbc2.jdbc.SybProperty;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.Serializable;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.BinaryRefAddr;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.StringRefAddr;

import javax.sql.ConnectionPoolDataSource;
import javax.sql.PooledConnection;

/**
 * SybConnectionPoolWrapperDataSource
 *
 * 09-Jul-2003 - Gordon McKinney - Created
 *
 */
public class SybConnectionPoolWrapperDataSource extends
SybConnectionPoolDataSource
    implements Serializable, Referenceable
{
    static final String OBJECT_FACTORY_NAME;
    static final String CONNECTION_POOL_NAME;

    static
    {
        // Our object factory with enhanced JNDI reference handling
        OBJECT_FACTORY_NAME  =
SybObjectFactoryWrapper.class.getName();

        // Must be the original class otherwise the object factory
gets confused.
        CONNECTION_POOL_NAME =
SybConnectionPoolDataSource.class.getName();
    }

    public SybConnectionPoolWrapperDataSource()
    {
        super();
    }

    public Reference getReference() throws NamingException
    {
        // Get normal reference
                Reference superReference = super.getReference();

                // Create a new reference to the original sybase connection pool
                // but with our enhanced object factory.
        Reference ret = new Reference(CONNECTION_POOL_NAME,
OBJECT_FACTORY_NAME, null);

                // Copy the existing reference parameters
                for(int i=0; i<superReference.size(); i++)
                {
                        ret.add( superReference.get(i) );
                }

                //
                // Suplimentary parameters.
                // This is stuff the sybase (in their wisdom) didn't
                // include!  Also see SybObjectFactoryWrapper
                // TODO Add your own Sybase parameters as desired
                //
                ret.add(new StringRefAddr("CHARSET", getCHARSET()));
                ret.add(new StringRefAddr("CHARSET_CONVERTER_CLASS",
getCHARSET_CONVERTER_CLASS()));
                ret.add(new StringRefAddr("JCONNECT_VERSION",
getJCONNECT_VERSION()));

        return ret;
    }

Quote:}

__________________________________________________________________________________________________

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.Name;
import javax.naming.Reference;

import com.sybase.jdbc2.jdbc.SybDataSource;
import com.sybase.jdbc2.jdbc.SybObjectFactory;
import com.sybase.jdbc2.jdbc.SybProperty;

/**
 * SybObjectFactoryWrapper
 *
 * 10-Jul-2003 - Gordon McKinney - Created
 */
public class SybObjectFactoryWrapper extends SybObjectFactory
{

        public SybObjectFactoryWrapper()
        {
                super();
        }

        protected Object getObjectUsingReference(Reference reference, Name
name, Context context, Hashtable hashtable)
        {
            SybDataSource ret =
(SybDataSource)super.getObjectUsingReference(reference, name, context,
hashtable);

                //
                // Suplimentary parameters
                // See SybConnectionPoolWrapperDataSource
                // TODO Add your own Sybase parameters as desired
                //
                ret.setCHARSET((String)reference.get("CHARSET").getContent());
                ret.setCHARSET_CONVERTER_CLASS((String)reference.get("CHARSET_CONVERTER_CLASS").getContent());
                ret.setJCONNECT_VERSION((String)reference.get("JCONNECT_VERSION").getContent());

                return ret;
        }

Quote:}

__________________________________________________________________________________________________
 
 
 

1. No suitable driver? w jconnect/jndi

Hi, does anyone know what this message means?
I was just trying to use ldap to get my sybase server connection information
and make a connection(code fragment copy from the jconnect programmer
guide).

bag/user/l/lhu/bin 3$ java sybldap SOMEARG
java.sql.SQLException: No suitable driver
        at java.lang.Throwable.fillInStackTrace(Native Method)
        at java.lang.Throwable.<init>(Throwable.java:94)
        at java.lang.Exception.<init>(Exception.java:42)
        at java.sql.SQLException.<init>(SQLException.java:64)
        at java.sql.DriverManager.getConnection(Compiled Code)
        at java.sql.DriverManager.getConnection(DriverManager.java:106)
        at sybldap.main(sybldap.java:24)

My
CLASSPATH=.:/tmp/jconnect/5.2.1/classes/jconn2.jar:/tmp/jndi/1.2.1/lib/jndi.
jar:/tmp/jndi/lib/ldap.jar
and the compilation was fine.

and the source ...

import javax.naming.*;
import java.util.Properties;
import java.io.*;
import java.util.*;
import java.sql.*;
import com.sybase.*;

public class sybldap {
    public static void main(String[] args) {
        if (args.length < 1) {
     System.err.println("usage: java Lookup <name_of_object>");
     System.exit(-1);
 }

        Properties props = new Properties();

props.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"
);
        props.put(Context.PROVIDER_URL, "ldap://myldapserver:389");
        props.put("user", "");
        props.put("password", "");

 try {
            Connection con =
DriverManager.getConnection("jdbc:sybase:jndi:ldap://myldapserver:398/cn='SY
BASE1',o=sybase,ou=Apps,o=ACME",props);
 } catch (Exception e) {
     e.printStackTrace();
 }
    }

2. System error variables

3. jConnect and Pooled Sybase Connections

4. Sorting

5. JDBC and SYBASE - Best Solution jConnect or other?

6. why can not display chinese content from access in widnows 2000 eng verson?

7. JDBC jConnect driver / Sybase System 11 / autoCommit

8. Microsoft SQL Server Costs

9. connection pool jndi registration a must?

10. JNDI pooling datasource in Tomcat

11. Getting a pooled connection WITHOUT JNDI

12. connection pool jndi registration a must?

13. How to deploy conn pool via JNDI