« How to recover dual-boot in Windows XP and Windows Server 2008 | Main | How to change IP address using command prompt »

Introduction to Enterprise JavaBeans 3.0 - for JDeveloper 10.1.3.3


Introduction to Enterprise JavaBeans 3.0 - for JDeveloper 10.1.3.3



When you are reading the Introduction to Enterprise JavaBeans 3.0 in otn.oracle.com you will find that there is no step by step guidance to put the code in JDeveloper.



The version of JDeveloper I am using is 10.1.3.3 and the files that I am running with only Session Bean and its simple client.


 

For CalculateEJB.java:



import javax.ejb.Remote;



@Remote

public interface CalculateEJB {

    String incrementValue();

}



For CalculateEJBLocal.java:


import javax.ejb.Local;


@Local

public interface CalculateEJBLocal {

}



For CalculateEJBBean.java:


import javax.ejb.Stateless;


@Stateless(name="CalculateEJB")

public class CalculateEJBBean implements CalculateEJB, CalculateEJBLocal {

    public CalculateEJBBean() {

    }

   

    int value = 0;

    public String incrementValue()

    {

        value++;

        return "value incremented by 1";

    }


}



At last, for the simple client:


import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingException;


public class CalculateEJBClient {

    public static void main(String [] args) {

        try {

            final Context context = getInitialContext();

            CalculateEJB calculateEJB =   

                   (CalculateEJB)context.lookup("CalculateEJB");

            // Call any of the Remote methods below to access the EJB

            System.out.println( calculateEJB.incrementValue(  ) );

        } catch (Exception ex) {

            ex.printStackTrace();

        }

    }


    private static Context getInitialContext() throws NamingException {

        // Get InitialContext for Embedded OC4J

        // The embedded server must be running for lookups to succeed.

        return new InitialContext();

    }

}


 


Complete sample download.

Post a comment

About This Entry

This page contains a single entry from the blog posted on June 10, 2008 10:54 AM.

The previous post in this blog was How to recover dual-boot in Windows XP and Windows Server 2008.

The next post in this blog is How to change IP address using command prompt.

Many more can be found on the main index page or by looking through the archives.

Top Tags

Powered by
Movable Type and Oracle