4 Getting Started with the Application
To develop a Java application that connects to the Oracle Database, you must ensure that certain components are installed.
This chapter covers the following topics:
What You Need to Install
To develop the sample application, you need to install the following products and components:
-
Oracle Database
-
J2SE or JDK
-
Apache Maven
-
IntelliJ
-
Apache Tomcat
Oracle Database
To develop the Java web application, you need a working installation of Oracle Database along with the HR schema. There are two ways you can install the Oracle Database.
Option 1. Oracle Autonomous Database
The Oracle Database Cloud Services offer access to Oracle Cloud Free Tier which provides services of two Autonomous Databases for an unlimited time. Oracle Autonomous Database is an all-in-one cloud database solution for data marts, data lakes, operational reporting, and batch data processing. Oracle uses machine learning to completely automate all routine database tasks—ensuring higher performance, reliability, security, and operational efficiency. You can get access to a working Autonomous Database in just a few minutes. After signing up, you will have access to your choice of Autonomous Transaction Processing or Autonomous Data Warehouse databases.
This guide uses Autonomous Transaction Processing database to run the HR Application.
See Also:
Provisioning an ATP Database instance video for instructionsOption 2: Oracle Database Free Available on OTN
As an alternate option, you can install Oracle Database Free on your system.
Install the HR schema
The HR web application uses the tables and data from the HR sample schema provided by Oracle. You need to install the HR schema in your database.
Once you provision an Autonomous Database or install Oracle Database Free, see Installing HR Schema for detailed instructions to install the sample schema.
J2SE or JDK
To create and compile Java applications, you need the full Java 2 Platform, Standard Edition, Software Development Kit (J2SE SDK), formerly known as the Java Development Kit (JDK).
- Download and install the Java SE. Refer http://www.oracle.com/technetwork/java/javase/downloads/index.html.
- Set the
PATH
environment variable for JDK. Refer JDK Installation Instructions for Windows for detailed instructions.
JDBC Drivers
You need to download certain JDBC drivers for running the HR application.
pom.xml
file:
<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc<groupId>
<artifactId>ojdbc8-production</artifactId>
<version>19.7.0.0</version>
<type>pom</type>
</dependency>
</dependencies>
The ojdbc8-production
pulls all the required JDBC jars from the Maven
Central Repository. For more information, see the Maven Central Guide.
Integrated Development Environment
Note:
To download and install IntelliJ Idea, see https://www.jetbrains.com/idea/.Web Server
The sample application developed in this guide uses JavaServer Pages (JSP) technology to display information and accept input from users. To deploy these pages, you need a Web server with a servlet and JSP container.
This guide uses the Apache Tomcat server for deploying the JSP pages.
For more information on how to download and install Apache Tomcat, refer to http://tomcat.apache.org/.
Github Repository Details
The source files for the HR Web Application is available on GitHub.
Table 4-1 Github Repository Details
Name and Location | Details |
---|---|
HRWebApp | This repository contains the complete code samples of the application. |
Import the Application in IntelliJ
Import the application in IntelliJ as follows:
- Open IntelliJ and select Open or Import.
- Navigate to the location where the HRWebApp is downloaded. Select HRWebApp and click OK.
- A project with all the files required to build the HR Web application is displayed.
Compile the Application in IntelliJ
The code requires a few updates before you compile the application.
Run the HR Web Application
The HR Web application is run using the Tomcat server.
- Navigate to the HRWebApp folder on your local machine. Under the
target folder, locate
JdbcWebSamples.war
file. - Place
JdbcWebSamples.war
file underTOMCAT_HOME/webapps/
. - Navigate to the HRWebApp folder on your local machine. Locate
tomcat-users.xml
file. - Place
tomcat-users.xml
file underTOMCAT_HOME/conf/
. - Start the tomcat server.
- Once the tomcat is started, access the HR web application from a
browser using the URL
http://localhost:8080/JdbcWebSamples/.
- Login to the application with either hradmin or
hrstaff user.
Note:
- For more information about the hradmin and hrstaff users, see Overview of the HR Web Application and Create Login and Logout Functionality.
- Refer tomcat-users.xml file for the username and password information required to login to the HR Web Application.
- HR Web Application has several functionalities. List All displays the employees' details such as Employee_id, First_name, Last_Name, Email, Phone_number, Job_id, Salary etc. The details are retrieved from the Employees table and displayed on a web page. See the screenshot below that shows List All functionality.
- Similarly, verify the remaining functionalities such as Search by ID, Update Employee Record and Increment Salary by giving appropriate inputs.