Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I NEED SOME HELP Note : For each query in your assignment, make sure you handle the errors and display the proper message including the

I NEED SOME HELP

Note: For each query in your assignment, make sure you handle the errors and display the proper message including the error_code and the error message.

try{

...

}

catch (SQLException& sqlExcp) {

cout << sqlExcp.getErrorCode() << ": " << sqlExcp.getMessage();

}

Connecting to an Oracle database from a C++ Program

In your function main(), create a connection to your database.

First, declare the environment and the connection variables.

Environment* env = nullptr;

Connection* conn = nullptr;

Define and initialize the variable to store the username, password, and the host address.

string user = "username";

string pass = "password";

string constr = "myoracle12c.senecacollege.ca:1521/oracle12c";

Use the same Oracle username and password that you use for your labs and assignments.

Create the environment and the connection. Make sure you handle any errors may be thrown as you program is executed.

env = Environment::createEnvironment(Environment::DEFAULT);

conn = env->createConnection(user, pass, constr);

Remember to terminate and close the connection and the environment, when your program terminates.

env->terminateConnection(conn);

Environment::terminateEnvironment(env);

You will implement the following functions:

int menu(void);

The menu() function returns an integer value which is the selected option by the user from the menu. This function displays the following menu options:

Find Employee

Employees Report

Add Employee

Update Employee

Remove Employee

Exit

Before printing the menu, display the following title on the screen

********************* HR Menu *********************

Prompt the user to enter an option (0 to 5). If the user enters an incorrect option, the user is asked to enter an option again. When the user enters a correct option (0 to 5), the function returns the selected value.

If the user selects 0 (Exit), the program terminates.

Every time you call this function, the menu is displayed and the user is prompted to enter a value between 0 and 5. The function keeps asking the user enter a value until the user enters a correct number.

int findEmployee(Connection *conn, int employeeNumber, struct Employee *emp);

This function receives an OCCI pointer (a reference variable to an Oracle database), an integer number as the employee number, and a pointer to a variable of type Employee. The function returns 0 if the employee does not exist. It returns 1 if the employee exits.

To store the employee data in the findEmployee() function, we use a pointer that refers to a variable of type structure called Employee. The Employee structure has the following members:

struct Employee{

int employeeNumber;

char lastName[50];

char firstName[50];

char extension[10];

char email[100];

char officecode[10];

int reportsTo[100];

char jobTitle[50];

};

The ReportsTo member stores the employee ID of the employee who is the manager of the given employee number.

If the employee exists, store the employee data into the members of an Employee variable using the third parameter in the findEmployee() function which references to that variable of type Employee.

void displayEmployee(Connection *conn, struct Employee emp);

If the user selects option 1, prompt the user to enter a value for the employee number. Then, call function findEmployee() to check if the employee with the given employee number exists. If the returning value of function findEmployee() is 0, display a proper error message.

Sample error message:

Employee 1122 does not exist.

Otherwise, call the function displayEmployee() to display the employee information.

This function receives a Connection pointer (a reference variable to an Oracle database) and the members of a variable of type Employee and displays all members of the emp parameter.

See the following sample output:

******************** HR Menu ********************

1) Find Employee

2) Employees Report

3) Add Employee

4) Update Employee

5) Remove Employee

0) Exit

Enter an option (0-5): 1

Enter Employee Number: 1002

void displayAllEmployees(Connection *conn);

If the user selects option 2 (Employees Report), call function displayAllEmployees().

This function receives a pointer of type OCCI Conection (a reference variable to an Oracle database) and displays all employees information if exist.

*********************HR Menu*********************

1) Find Employee

2) Employees Report

3) Add Employee

4) Update Employee

5) Remove Employee

0) Exit

Enter an option (0-5):

Note: For this report, you may need to query more than one table (join).

If the query does not return any rows, display a proper message:

There is no employees information to be displayed.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions