Moving to Enterprise JavaBeans 187
17.3.1 Adding Behavior to Your EJB
When you create an EJB in the EJB development environment, a set of
required methods for the bean is automatically created. You can modify these
methods and add new remote (business) and home methods of your own.
Adding methods in the EJB development environment is similar to adding
methods elsewhere in VisualAge for Java. Once you have created remote
(business) methods or home methods for your classes and interfaces, you
can promote the methods to the remote and home interfaces from the Bean
class without editing the remote and home interfaces directly.
Follow these steps to add a new method:
1. In the Types pane of the EJBs page, select the class or interface to which
you want to add a method.
2. Click mouse button 2, then select Add Method from the pop-up menu.
The Add Method SmartGuide appears.
3. Follow the SmartGuide instructions on creating a new method.
4. Click Finish to create and compile the new method.
If you want to remove a remote method from the remote interface, select the
method and then select Methods-> Remove From ->EJB Remote Interface.
If you want to remove a home method from the home interface, select the
method and then select Methods-> Remove From ->EJB Home Interface.
Before we add methods to our EJB, we are going to define some properties
that are used later on. We add the following properties to the
EmployeeIDBean class:
private Connection _connection;
private static String _jdbcURL = "jdbc:db2:sample";
private static String _jdbcDriverName = "COM.ibm.db2.jdbc.app.DB2Driver";
public String userid;
private Statement _statement;
and an import statement:
import java.sql.*;
In our EmployeeID bean, we are going to add two methods:
• getConnection()
This method loads the JDBC driver and returns a connection