A P P E N D I X C |
Creating the Tutorial with an Oracle Database |
This appendix describes the steps you must perform to create and run the DiningGuide tutorial with an Oracle database. The topics covered are:
Note - There are several references in this book to the DiningGuide application files. These files include a completed version of the tutorial application, a readme file describing how to run the completed application, and SQL script files for creating the required database tables. These files are compressed into a zip file you can download from the Sun ONE Studio 5 Developer Resources portal at http://forte.sun.com/ffj/documentation/tutorialsandexamples.html |
Configure Sun ONE Application Server 7 to connect to the Oracle database by performing the required JDBC-related actions in the application server environment. These include:
Enabling a JDBC driver means putting the driver library in the Sun ONE Studio 5 and Sun ONE Application Server 7 class paths. To do this, you need the Oracle Type 4 JDBC driver library (the classes12.zip file). You can download this driver from the Oracle portal. Copy the JDBC Type 4 driver into the program files of Sun ONE Studio 5 before you start the IDE.
To enable the Oracle Type 4 JDBC driver:
1. Copy the Oracle Type 4 driver library to the s1studio-install-directory/lib/ext directory.
For example, copy the classes12.zip file to c:\Sun\studio5_se\lib\ext.
Note - You must have root or administrator privileges to write to the Sun ONE Studio 5 home directories. |
3. In the Runtime pane of the Explorer, select your application server instance.
It is labeled app-server-name (app-server-host:app-server-port). For example, the default server is server1 (localhost:4848), or a standard user's server could be MyServer (localhost:4855).
4. Display the properties of the application server instance.
The property window is usually below the Explorer window. Selecting the node displays the properties in the window. If the window is not there, right-click the server instance node and choose Properties.
5. Open the property editor for the Classpath Suffix property.
Click on the value field of this property, then on the ellipsis button that appears. The Classpath Suffix editor window is displayed.
6. Click the Add JAR/ZIP button.
Use the Add JAR File file finder to locate your classes12.zip file.
7. Select the classes12.zip file and click OK.
8. Click OK to close the property editor window. J
To create the JDBC connectivity resources or the EJB tier of the tutorial, you must connect the IDE to the Oracle database. You can either connect before creating these components or during the creation process. Here is how you connect to the database beforehand:
1. Make sure the Oracle server is running.
2. In the Runtime pane of the Explorer, expand the Databases node and its Drivers subnode.
A node labeled Oracle thin is displayed.
If this node has a red strike across it, you have not enabled the Oracle JDBC driver properly. Follow the procedures in Enabling the Oracle Type 4 JDBC Driver.
3. Right-click this node and choose Connect Using.
The New Database Connection dialog box is displayed.
4. Make sure Oracle thin is selected in the name field.
5. Fill in the property values for Database URL, User, and Password.
For example, the following values are correct for a locally installed Oracle database with a SID of "extut," and the default Oracle login of "scott" for User and "tiger" for Password: (1521 is the standard Oracle port number.)
6. Enable the Remember password during this session option.
The New Database Connection dialog box should look like this:
The new Oracle thin driver node is displayed, labeled jdbc:oracle:thin:@hostname:1521:sid [Username on Password].
9. Expand this node and its Tables subnode.
The tables in the database, including the RESTAURANT and CUSTOMERREVIEW tables, are displayed.
To create a JDBC connection pool so that the business objects in the system can share database access, you first define a JDBC connection pool with information related to your database, then register it with Sun ONE Application Server 7.
Note - Before starting this procedure, make sure both the admin server and the application server are running (refer to ). |
To create an Oracle JDBC connection pool for this tutorial:
1. In the Runtime pane of the Explorer, expand the Server Registry, Installed Servers, and Sun ONE Application Server 7 nodes.
2. Right-click the Unregistered JDBC Connection Pools node and choose Add New JDBC Connection Pool.
This opens the New JDBC Connection Pool wizard.
3. Type OraclePool for the JDBC Connection Pool Name.
4. Enable the Extract From Existing Connection option.
5. Select the Oracle thin string from the pull-down menu.
A window is displayed, asking whether you want to register this resource.
The JDBC Connection Pool Registration dialog box is displayed.
8. Select the server instance you wish to register to from the list and click Register.
When the connection pool is registered, a message is displayed indicating success.
9. Click the Close button to close the window.
The registered OraclePool connection pool is displayed.
If you do not see the OraclePool connection pool, right-click the Registered JDBC Connection Pools node and choose Refresh List.
A JDBC data source (also called a JDBC resource) lets you make connections to a database with the getConnection() method. Before creating a data source, make sure both the admin server and the application server are running.
To create a JDBC persistent manager:
1. If necessary, expand the Server Registry, Installed Servers, and Sun ONE Application Server 7 nodes in the Explorer's Runtime page.
2. Right-click the Unregistered JDBC Data Sources node and choose Add New Data Source.
This opens the New JDBC Resource wizard.
3. Enable the Use Existing JDBC Data Source option, and select OraclePool from the list.
4. Type jdbc/jdbc-oracle for the JNDI name and select True in the Enabled field.
A window is displayed, asking whether you want to register this resource.
The Persistence Manager Registration dialog box is displayed.
7. Select the server instance you wish to register to from the list and click Register.
When the data resource is registered, a message is displayed indicating success.
8. Click the Close button to close the window.
The jdbc/jdbc-oracle node is displayed under the Registered JDBC DataSources node. If you don't see it, right-click the JDBC Data Sources node and choose Refresh List.
A persistent manager is a component responsible for the persistence of the entity beans installed in the container. Before creating a persistent manager, make sure both the admin server and the application server are running.
To create a JDBC persistent manager:
1. If necessary, expand the Server Registry, Installed Servers, Sun ONE Application Server 7, and the nodes in the Explorer's Runtime page.
2. Right-click the Unregistered persistent managers node and choose Add a Persistent Manager.
This opens the New Persistence Manager wizard.
3. Enable the Use Existing JDBC Resource option, and select jdbc/jdbc-oracle from the list.
4. Type jdo/OraclePm for the JNDI name and select True in the Enabled field.
A window is displayed, asking whether you want to register this resource.
The Persistence Manager Registration dialog box is displayed.
7. Select the server instance you wish to register to from the list and click Register.
When the persistent manager is registered, a message is displayed indicating success.
8. Click the Close button to close the window.
The jdo/OraclePm node is displayed under the Registered Persistence Managers node. If you don't see it, right-click the node and choose Refresh List.
The DiningGuide tutorial uses two database tables, which you must create in an Oracle Server database. The instructions that follow describe how to use the provided SQL script to create your tables. Microsoft Windows users can copy and paste the SQL script provided in Appendix B to create these tables. Solaris and Linux users can use a script file, diningguide_ora.sql, which is available within DiningGuide application files.
To install the tutorial tables in an Oracle database on Microsoft Windows systems:
1. Open the Oracle Console by choosing Start Programs
Oracle (your version) Application Development
SQL Plus.
2. Log in to SQL Plus using your user name and password.
For example, use the user name (scott) and password (tiger) for the default Oracle installation.
3. When the SQL prompt appears, copy the script from Chapter B and paste it next to the prompt.
To install the tutorial database on Solaris or Linux environments:
1. Unzip the DiningGuide.zip file from the Developer Resources portal.
For example, unzip it to the /MyZipFiles directory.
$ cd your-unzip-dir/DiningGuide/db $ sqlplus db-userid/db-password@db-servicename @diningguide_ora.sql |
$ cd /MyZipFiles/DiningGuide/db $ sqlplus scott/tiger@MyDB @diningguide_ora.sql |
The two DROP statements will generate errors, but they are harmless.
This section lists the changes to required to create the EJB tier using an Oracle database. TABLE C-1 lists the sections and the changes required.
Use the Oracle schema to create the Customerreview entity bean. |
|
This section lists the changes to required to create the web service using an Oracle database. TABLE C-2 lists the sections and the changes required.
Start SQLPlus, log into your database, and test the insertion of the record, as described. |
Copyright © 2003, Sun Microsystems, Inc. All rights reserved.