1.Log in to Oracle using the user name osmsusr and password osmspass by entering the following command:

# sqlplus osmsusr/osmspass@osmsdb_ora

2.In the Oracle database identified by the Oracle SID, osmsdb_ora, create a table named USERS, and then sequence with the osmsusr user by entering the following commands:

SQL> Create sequence hibernate_sequence start with 10 increment by 1 min value 10 maxvalue 999999999999;

SQL> Create table USERS ( user_id number(10) not null, first_name varchar(30) not null, last_name varchar2(30) not null);

SQL> Alter table USERS add ( constraint user_primary_key primary key(user_id) using index);

NOTE: The Oracle sequence, HIBERNATE_SEQUENCE, is used to generate a primary key for the table named USERS.

Creating a Simple Application in Tomcat

You must create a simple application within Tomcat to facilitate verification of this functionality. This simple application implements the insert, update, select, and delete functions for the USERS table in the MySQL or Oracle database.

Use the following steps to create a simple application in Tomcat:

1.Create a directory named $CATALINA_HOME/webapps/SimpleDemo that contains the appropriate subdirectories by entering the following commands:

#mkdir $CATALINA_HOME/webapps/SimpleDemo

#mkdir $CATALINA_HOME/webapps/SimpleDemo/META-INF

#mkdir $CATALINA_HOME/webapps/SimpleDemo/WEB-INF

#mkdir $CATALINA_HOME/webapps/SimpleDemo/WEB-INF/classes

#mkdir $CATALINA_HOME/webapps/SimpleDemo/WEB-INF/lib

2.Configure the MySQL or Oracle data source by creating a file named

$CATALINA_HOME/conf/Catalina/localhost/SimpleDemo.xml. Add the following lines, depending on whether your database is MySQL or Oracle:

For a MySQL database server:

<Context>

<Resource

name="MySqlDS"

type="javax.sql.DataSource"

password="osmspass"

driverClassName="com.mysql.jdbc.Driver"

maxIdle="10"

maxWait="5000"

username="osmsusr"

url="jdbc:mysql://IP_OR_HOSTNAME_OF_DB_SERVER:3306/osmsdb" maxActive="15"/>

</Context>

For an Oracle database server:

<Context>

<Resource

name="OracleDS"

type="javax.sql.DataSource"

password="osmspass"

driverClassName="oracle.jdbc.driver.OracleDriver"

maxIdle="10"

Installing, Configuring, and Managing Web Server Middleware Stack Components 37