Skip to content

Commit e2b0500

Browse files
committed
2 parents be11320 + eb21318 commit e2b0500

File tree

4 files changed

+137
-4
lines changed

4 files changed

+137
-4
lines changed
68.9 KB
Loading

java/HRWebApp/Readme.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22

33
**HR Web Application** is the Java application that uses Oracle Java Database Connectivity (JDBC), Universal Connection Pool (UCP), and Oracle Java in the Database (OJVM) with Oracle Database 12c Release 2.
44

5-
It is a light weight web application that uses the MVC (Model, View, Controller) architecture and all the latest tools and technologies. The presentation layer uses HTML that internally uses JavaScript, JQuery, and CSS to display the results. The controller will be a servlet that talks to the Oracle Database through the Java Beans. Maven is used for building the application.
5+
It is a light weight web application that uses the MVC (Model, View, Controller) architecture and all the latest tools and technologies. The presentation layer uses HTML that internally uses JavaScript, JQuery, and CSS to display the results. The controller will be a servlet that talks to the Oracle Database through the Java Beans. Maven is used for building the application. The Architecture of the HR Web Application is depicted in the figure.
66

7-
This Java application leverages HR schema and Employees table of the Oracle Database 12c Release 2. It is intended to help the HR team of AnyCo Corporation to store the details of all the employees, add any new employee, update the employee details, delete any employee, or provide a salary hike to all employees. It has two users **HRStaff** and **HRAdmin** who have different roles and access to the application.
7+
![Architecture of HR Web Application](https://github.com/oracle/oracle-db-examples/blob/master/java/HRWebApp/HRWebApp_Architecture.jpg)
88

9-
The application has the following functionalities.
9+
This Java application leverages HR schema and Employees table of the Oracle Database 12c Release 2. It is intended to help the HR team of AnyCo Corporation to store the details of all the employees, add any new employee, update the employee details, delete any employee, or provide a salary hike to all employees. There are two users **HRStaff** and **HRAdmin** who have different privileges and access to the application.
1010

11+
**HRStaff** has read access to the application and do not have any privileges to update/delete an employee record. HRStaff has privileges to perform the following functions.
1112

1213
* **About** :
1314
This page provides an overview of the HR Application and explains the various functionalities it offers.
1415

1516
* **List All Employees** :
16-
Use this functionality to retrieve employees information. It lists the employee information such as Employee_ID, First_Name, Last_Name, Email, Phone_Number, Job_Id, and Salary.
17+
This functionality retrieves information about the employees. It lists the employee information such as Employee_ID, First_Name, Last_Name, Email, Phone_Number, Job_Id, and Salary.
1718

1819
* **Search By Employee ID:** :
1920
Use Employee ID that is the primary key of Employees table to search for a particular employee.
2021

22+
**HRAdmin** has a full control on the application and has both read and update privileges. HRAdmin has access to all functionalities of the application. HRAdmin can do the following functions in addition everything that HRStaff can do.
23+
2124
* **Update Employee Record:** :
2225
Search for a particular employee based on the name of the employee. You can then update employee details in the record, such as first_name, last_name, email, phone_number, job_id and salary using this function.
2326

java/ojvm/InternalT2Driver.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.*/
2+
/*
3+
DESCRIPTION
4+
The server-side Type 2 (T2S) driver (aka KPRB driver) is for Java in the
5+
database. Java running in the database session uses the KPRB driver or
6+
T2S driver to access data, locally.
7+
We furnish the server-side thin JDBC (aka Type 4 server driver) for
8+
accessing data in other session in the same database or a remote Oracle
9+
database.
10+
11+
Step 1: Connect to SQLPLUS using the database USER/PASSWORD.
12+
Make sure to have InternalT2Driver.sql accessible on the
13+
client side to execute.
14+
Step 2: Run the SQL file after connecting to DB "@InternalT2Driver.sql"
15+
16+
NOTES
17+
Use JDK 1.6 and above
18+
19+
MODIFIED (MM/DD/YY)
20+
nbsundar 03/23/15 - Creation (kmensah - Contributor)
21+
*/
22+
import java.sql.Connection;
23+
import java.sql.ResultSet;
24+
import java.sql.SQLException;
25+
import java.sql.Statement;
26+
27+
import oracle.jdbc.driver.OracleDriver;
28+
import oracle.jdbc.pool.OracleDataSource;
29+
30+
31+
public class InternalT2Driver {
32+
33+
static public void jrun() throws SQLException {
34+
// For testing InternalT2Driver
35+
// test("jdbc:oracle:kprb:@");
36+
test("jdbc:default:connection");
37+
}
38+
/*
39+
* Shows using the server side Type 2 driver a.k.a KPRB driver
40+
*/
41+
static public void test(String url) throws SQLException {
42+
Connection connection = null;
43+
try {
44+
System.out.println("Connecting to URL " + url);
45+
// Method 1: Using OracleDataSource
46+
OracleDataSource ods = new OracleDataSource();
47+
ods.setURL(url);
48+
connection = ods.getConnection();
49+
System.out.println("Method 1: Getting Default Connection "
50+
+ "using OracleDataSource");
51+
// Perform database operation
52+
printEmployees(connection);
53+
54+
// Method 2: Using defaultConnection() method
55+
OracleDriver ora = new OracleDriver();
56+
connection = ora.defaultConnection();
57+
System.out.println("Method 2: Getting Default Connection "
58+
+ "using OracleDriver");
59+
// Perform database operation
60+
printEmployees(connection);
61+
}
62+
finally {
63+
if (connection != null) connection.close();
64+
}
65+
}
66+
67+
/*
68+
* Displays employee_id and first_name from the employees table.
69+
*/
70+
static public void printEmployees(Connection connection) throws SQLException {
71+
ResultSet resultSet = null;
72+
Statement statement = null;
73+
try {
74+
statement = connection.createStatement();
75+
resultSet = statement.executeQuery("SELECT employee_id, first_name FROM "
76+
+ "employees order by employee_id");
77+
while (resultSet.next()) {
78+
System.out.println("Emp no: " + resultSet.getInt(1) + " Emp name: "
79+
+ resultSet.getString(2));
80+
}
81+
}
82+
catch (SQLException ea) {
83+
System.out.println("Error during execution: " + ea);
84+
ea.printStackTrace();
85+
}
86+
finally {
87+
if (resultSet != null) resultSet.close();
88+
if (statement != null) statement.close();
89+
}
90+
}
91+
}
92+
93+

java/ojvm/InternalT2Driver.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Rem InternalT2Driver.sql
2+
Rem
3+
Rem Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4+
Rem
5+
Rem NAME
6+
Rem InternalT2Driver.sql
7+
Rem
8+
Rem DESCRIPTION
9+
Rem SQL for invoking the method which gets a server side connection to
10+
Rem internal T2 Driver
11+
Rem
12+
Rem MODIFIED (MM/DD/YY)
13+
Rem nbsundar 03/23/15 - Created
14+
Rem kmensah 03/23/15 - Contributor
15+
16+
rem Reads the content of the Java source from InternalT2Driver.java
17+
rem then compiles it
18+
connect hr/hr
19+
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED InternalT2Driver_src AS
20+
@ InternalT2Driver.java
21+
/
22+
23+
show error
24+
25+
rem A wrapper (a.k.a. Call Spec), to invoke Java
26+
rem function in the database from SQL, PL/SQL, and client applications
27+
CREATE OR REPLACE PROCEDURE InternalT2Driver_proc AS
28+
LANGUAGE JAVA NAME 'InternalT2Driver.jrun ()';
29+
/
30+
31+
rem Running the sample
32+
connect hr/hr
33+
SET SERVEROUTPUT ON SIZE 10000
34+
CALL dbms_java.set_output (10000);
35+
36+
execute InternalT2Driver_proc;
37+

0 commit comments

Comments
 (0)