Oracle8i Enterprise JavaBeans Developer's Guide and Reference Release 3 (8.1.7) Part Number A83725-01 |
Library | Service | Contents | Index

## JNDI Connection Basics

The client example in Chapter 2 showed how to connect to Oracle, start a database server session, and activate an object using a single URL specification. This was performed through the following steps:

    1. Hashtable env = new Hashtable();
    2. env.put(javax.naming.Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    3. env.put(javax.naming.Context.SECURITY_PRINCIPAL, username);
    4. env.put(javax.naming.Context.SECURITY_CREDENTIALS, password);
    5. env.put(javax.naming.Context.SECURITY_AUTHENTICATION,

    	ServiceCtx.NON_SSL_LOGIN);
    6. Context ic = new InitialContext(env);
    7. HelloHome hello_home =
        (HelloHome) ic.lookup("sess_iiop://localhost:2481:ORCL/test/myHello");
       myHello hello = hello_home.create ();
    8. System.out.println(hello.helloWorld());

In this example, there are four basic operations:

- Lines 1-5 set up an environment for the JNDI initial context.

- Line 6 creates the JNDI initial context.

- Line 7 looks up a published object. (See "URL Syntax" for a discussion of the URL syntax.)

- Line 8 invokes a method on the object.

When a client looks up an object through the JNDI `lookup` method, the client and server automatically perform the following logic:

- A session IIOP connection is created to the ORCL instance of the local host database.

- The server establishes a database session.

- The client is authenticated, using the NON_SSL_LOGIN protocol, with the username and password specified in the environment context.

- The published object, `/test/myHello`, is located in the session namespace and a reference to it is returned to the client.

When the client invokes a method--such as `helloWorld()`--on the returned reference, the server activates the object in the server.

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index