Link to home
Start Free TrialLog in
Avatar of context
context

asked on

Java: JDBC & JNDI: Retrieving a Context

Hi,

Am trying to retrieve a DataSource object (once it has been bound).

I believe I manage to bind the object successfully - a .bindings file is created in the relevant directory.
However, when I try to retrieve the object (doing a lookup), nothing is returned.

Maybe I'm just oversimplifying things...the MyDataSource class just extends DataSource and doesn't do much else.

Relevant code below:

      MyDataSource ds = new MyDataSource()
      ds.setDescription("Data Source");
      ds.setDataSourceName("jdbc/Oracle");
     
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
      env.put(Context.PROVIDER_URL, "file:c:\\JDBCDataSource");
     
      Context ctx = new InitialContext(env);

      // Register the data source to JNDI naming service
      // for application to use
      ctx.ind("jdbc/Oracle", ds);

    // The following call will return null
     DataSource  new_ds = (DataSource) ctx.lookup(jdbc/Oracle);



Thanks,


Andy
ASKER CERTIFIED SOLUTION
Avatar of patbin
patbin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial