Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2003
    Location
    Massachusetts
    Posts
    1

    Post Unanswered: Connecting to DB2 UDB Using Data Source

    I get the following error message:

    C:\jdbc\intentry>javac db2IntEntry.java

    C:\jdbc\intentry>java db2IntEntry
    java.lang.ClassCastException
    at COM.ibm.db2.jndi.DB2Context.bind(Unknown Source)
    at javax.naming.InitialContext.bind(InitialContext.ja va:355)
    at db2IntEntry.<init>(db2IntEntry.java:88)
    at db2IntEntry.main(db2IntEntry.java:140)


    when I execute the code below. Why Unknown Source?

    import COM.ibm.db2.jndi.*;
    import com.ibm.db2.jcc.DB2SimpleDataSource;

    // creates a DataSource object, sets its properties,
    // and registers it with a JNDI naming service.
    // DB2SimpleDataSource vds = (DB2SimpleDataSource)
    // Class.forName("com.ibm.db2.jcc.DB2SimpleDataSource ").newInstance();
    com.ibm.db2.jcc.DB2SimpleDataSource vds = new com.ibm.db2.jcc.DB2SimpleDataSource();
    vds.setServerName( "localhost" );
    vds.setPortNumber( 50000 );
    vds.setDatabaseName( "sample" );
    vds.setDescription( "A Sample data source" );

    // Programming Client Applications: Chapter 10. Programming in Java 273
    // JDBC 2.1 Core API Restrictions by the DB2 JDBC Type 4 Driver
    // javax.naming.Context: implemented by COM.ibm.db2.jndi.DB2Context
    Hashtable env = new Hashtable( 5 );
    env.put( Context.INITIAL_CONTEXT_FACTORY, "COM.ibm.db2.jndi.DB2InitialContextFactory" );

    Context ctx = new InitialContext( env );
    ctx.bind( "jdbc/db2", vds );

    DataSource ds = (DataSource)ctx.lookup( "jdbc/db2" );
    Connection con = ds.getConnection( "db2admin", "passwd");

    Please somebody help.


    Thanks a million.

    Stephen

  2. #2
    Join Date
    Apr 2003
    Location
    Melbourne, Australia
    Posts
    53
    Don't pass the env while creating the initial context and try

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •