Skip Headers

Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Looking Up an EJB 3.0 Resource Manager Connection Factory

Using EJB 3.0, you can look up a resource manage connection using resource injection (see "Using Annotations") or the `InitialContext` (see "Using Initial Context").

## Using Annotations

Example 19-29 shows how to use annotations and dependency injection to access an EJB 3.0 resource manager connection factory.

Example 19-29 Injecting an EJB 3.0 Resource Manager Connection Factory

    @Stateless public class EmployeeServiceBean implements EmployeeService
    {
        ...
        public void sendEmail(String emailAddress)
        {
            @Resource Session testMailSession;
            ...
        }
    }

## Using Initial Context

Example 19-30 shows how to use the initial context to look up an EJB 3.0 resource manager connection factory.

Example 19-30 Looking Up an EJB 3.0 Resource Manager Connection Factory

    @Stateless public class EmployeeServiceBean implements EmployeeService
    {
        ...
        public void sendEmail(String emailAddress)
        {
            InitialContext ic = new InitialContext();
            Session session = (Session) ic.lookup("java:comp/env/mail/testMailSession");
            ...
        }
    }

For more information, see "Configuring the Initial Context Factory".