You can use the Create a Java™ Bean that calls a stored procedure
wizard to create a Java Bean that calls a specific stored procedure.
Prerequisite: To use this wizard, you must be online, with
access to your database server.
- Switch to the Data perspective.
- In either the Data Project Explorer or the Database Explorer,
in the Stored Procedures folder, right-click the stored procedure that you
want to work with, and select Generate Java Bean from
the pop-up menu.
- On the Java Class Specification page of
the wizard, complete the following steps.
- In the Source Folder field, enter the
name of folder where you want to create the Java Bean or click Browse to
select the folder.
- In the Package field, enter the name
of Java package
in which you want to create your Java Bean or click Browse to
select the package. Leave this field empty to create the new class
in the default package.
- In the Name field, type a name for the
new class. To conform to Java conventions, the class name must start
with a capital letter.
- Specify whether the stored procedure returns a result set. If the procedure does return a result set, you can specify whether to
generate one of the following items:
- A helper class that provides better access to each column of the result
set.
- A parameter in the execute() method to limit the size
of the result set. If you do not select this option, the execute() method
retrieves all rows into the result set.
- Describe the result set. If you choose to generate
a helper class, you must describe the result set that is returned by the stored
procedure. You specify the columns that are in the result set on this page.
- Click Next.
- On the Specify Runtime Database Connection Information page, specify
whether to use a data source connection or a driver manager connection. A data source is defined in an application server that implements Java Database
Connectivity (JDBC), and is generally the preferred way for Web applications
to connect to a database because it provides pooled connections. When the
application initializes, the server requests a pool of database connections.
Each time a Web application requires a database connection, the server provides
one from the pool. When the Web application is done with the connection, it
releases the connection back to the pool. Because connecting to the database
is one of the slowest operations an application can perform, this approach
is usually the most efficient. In contrast, for a driver manager connection,
each time a Web application requires a database connection, it requests a
connection from the database server.
- Data source connection: Enter the Java Naming and Directory Interface (JNDI)
name of the data source, as defined in the server configuration.
- Driver manager connection: Type the fully-qualified class name
of the driver in the Driver Name field, and the associated JNDI address
in the URL field. For example, for DB2® enter COM.ibm.db2.jdbc.app.DB2Driver for
the Driver Name and jdbc:db2:SAMPLE for the URL.
- Specify how the method will provide user authentication. To run the stored procedure, you must supply a user ID and password
that are valid for the database. You can specify that the method will provide
a valid user ID and password within its execute() method.
This means that the Java Bean will always connect using the
same user ID and password. If you do not include the user ID and password
inside the execute() method, the application must provide
the user ID and password as input parameters to the execute() method.
- To include user authentication within the method, click Inside
the execute() method. Type a user ID and password in the appropriate fields
to access the database. The initial values are the ones originally used to
load the existing database model. The password will be masked when you type
it in the field.
- To require the user ID and password to be provided as parameters to
the execute()method, click By the execute() method's
caller
- Click Next.
- On the final page of the wizard, review the specifications for
the new Java Bean, then click Finish to
complete the wizard.
The wizard creates the Java Bean, along with all the necessary
deployment descriptors to build, run, and deploy it with your application.