DBS211 Introduction to Database Systems Assignment

Assignment Help Database Management System
Reference no: EM133187246

DBS211 Introduction to Database Systems

Database Application Development

Objective:
In this lab students learn:
• How to connect to anOracle server from a C++ program.
• How to write and execute SQL queries in a C++ program.

Connect to Oracle from Visual Studio C++

In this page, you create a username. Choose "Create New Windows User". You can define any username and password. Make sure you choose a password that can be remembered easily.You may see the following message:
Administrative password:[INS-30011] The ADMIN password entered does not
conform to the Oracle recommended standards.

Ignore the message and continue. Click on "Next".

In oracle base filed, you define where to install oracle. We use this location later to set up Oracle in Visual studio.
In the summary page, click on "Install" button.
Configure Visual Studio C++
Create a new project in VC++. Add your .cpp source file to your project. Then, go to the project properties:

Open "Configuration Manager", set "Active solution configuration" to "release" and "Active solution platform" to "x64".

In the project properties navigator, under C/C++, select "General". Add the following path to "Additional Include Directories".
C:\app\oracle\product\12.2.0\client_1\oci\include
"oracle" is the new windows user name that I created when installing Oracle Instant Client. If you have chosen a different user name, you will see your username in the C:\app\ folder.

In "Linker/General", add the following paths to "Additional Library Directories":
C:\app\oracle\product\12.2.0\client_1\oci\lib\msvc
C:\app\oracle\product\12.2.0\client_1\oci\lib\msvc\vc14

Clink "Apply" and then "Ok".
Connecting to an Oracle database from a C++ Program
• Create a new C++ project in Visual Studio. Add a source code named databaseConnection.cpp to your project.
• At the beginning of the C++ program, add the following libraries.
#include<iostream>
#include<occi.h>

usingoracle::occi::Environment;
usingoracle::occi::Connection;

usingnamespaceoracle::occi;
usingnamespace std;

• Before building the connection, you need to create an environment.
The Environment class provides an OCCI environment to manage memory and other resources for OCCI objects.
To define an environment instance define a reference of type Environment class.
Environment* env = nullptr;
env = Environment::createEnvironment(Environment::DEFAULT);

{
. . .
}
Environment::terminateEnvironment(env);
Terminate the environment when the connection is not required.
Opening and Closing a Connection
• To define a pointer (reference variable) to the Oracle database.
Connection* conn = nullptr;

• After creating the environment, create a connection.
conn = env->createConnection(user, pass, constr);
You must close and terminate the collection at the end of a working session.

env->terminateConnection(conn);

See the following code:
env = Environment::createEnvironment(Environment::DEFAULT);
// environment scope starts
{
conn = env->createConnection(user, pass, constr);
. . . // work with the database
env->terminateConnection(conn);
}
// environment scope ends
Environment::terminateEnvironment(env);
• To establish a connection to the Oracleserver write the following command:

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

You need to declare the following variables before creating the connection:
string user = "username";
string pass = "password";
stringconstr = "myoracle12c.senecacollege.ca:1521/oracle12c";

Use your Oracle username and password to set the variable user and pass.
• Use try-catch statements to handle any errors as a result of a connection failure.
try {
env = Environment::createEnvironment(Environment::DEFAULT);
{
conn = env->createConnection(user, pass, constr);
cout<<"Connection is Successful!"<<endl;
env->terminateConnection(conn);
}
Environment::terminateEnvironment(env);
}
catch (SQLException&sqlExcp) {
cout<<sqlExcp.getErrorCode() <<": "<<sqlExcp.getMessage();
}

Creatingand Terminating a Statement
• If the connection is successfully established, you can execute SQL queries in your C++ program. To execute a query, you need to create a statement object by calling a method of the connection object:
// define a reference to an object statement
Statement* stmt = nullptr;

// call method createStatement() to create an statement object
conn->createStatement("SELECT * FROM product_categories");

Termonate a statement before closing the connection when you do not need that object any more.
conn->terminateStatement(stmt);


Executing a Statement and Store the Query Result into a Result Set
• After declaring your SQL statement, you can execute it by calling the executeQuery() method:

stmt->executeQuery();
The executeQuery()method returns a ResultSet Object. To store the returning result set, you need to declare a ResultSet object.
// define a reference to an object resultset
ResultSet* rs = nullptr;
// store the result set
rs = stmt->executeQuery();
Fetching Data from a result set
• After calling the executeQuery( ) method, you can check if the result is empty or not.
if (!rs->next()) {
// if the result set is empty
cout<<"ResultSet is empty."<<endl;
}

The next() method of the ResultSet object is used to fetch the data. Every time you call this method, one row will be fetched from the result set if exists.
When there is no data to be fetched, this method returns false (0).
Be careful when you are using the next() method to see if the result set is empty. This method fetches a row from your result set. If you want to display all data in your result set, make sure you do not miss the first row.
If you want to print all the rows, you need a loop. See the following code:
if (!rs->next()) {
// if the result set is empty
cout<<"ResultSet is empty."<<endl;
}else{
while (rs->next()) {
cout<<"Category ID: "<<rs->getInt(1) <<" Category Name: "<<rs->getString(2) <<endl;
}
}
If you use the above code to check the result set and then read the data and print them out, you will miss printing the first since you have not printed the data fetch the first time you called the next() method.
To fix this problem, you first need to print the first row fetch by the first call of the next() method. Then, use a loop to read the rest of the result set.
if (!rs->next()) {
// if the result set is empty
cout<<"ResultSet is empty."<<endl;
}
else {
// if the result set in not empty
do {
cout<<"Category ID: "<<rs->getInt(1) <<" Category Name: "<<rs->getString(2) <<endl;
} while (rs->next()); //if there is more rows, iterate
}

Lab Requirements:

In this lab, you need to write a C++ program to execute the following queries and display the result returned by each query. For the output format, see the sample output.

1. Display Employee ID, First Name, Last Name, and Phone Number of all Employees who work as SA_REP. See the following Sample output. (Sort the report according to the employee number)

2. Display Employee Number, Last Name, and Phone Number, for all the managers.

Attachment:- Database Application Development.rar

Reference no: EM133187246

Questions Cloud

Schedule of cash receipts for may and june : Schedule of cash receipts for May and June. Round your intermediate computations and final answers to the nearest whole dollar
What amount of investment in sand would be reported : Pail reported on its general ledger Investment in Sand at $895000. What amount of Investment in Sand would be reported on the 12/31/21
What is the weight of equity in the capital structure : Company X has 2 million shares of common stock outstanding at a book value of $5 per share. What is the weight of equity in the capital structure
Prepare the journal entry made by poonamalie : he Poonamalie Company paid $3,200,000 in cash. Prepare the journal entry made by Poonamalie to record the business combination as a merger
DBS211 Introduction to Database Systems Assignment : DBS211 Introduction to Database Systems Assignment Help and Solution, Seneca College - Assessment Writing Service
Calculate the materials efficiency variance : Managers expected to pay $5 per kilogram, but ended up paying $6 per kilogram. Calculate the materials efficiency variance
Prepare the entries made by prance to record the events : The $448,000 estimated liability represented Step's best estimate of likely losses due to lawsuits pending as of January 3, 2012. Prepare the entries made
Provide the journal entries related to current tax : Dividend income of C12 000 was earned during 20X1 (not taxable). Provide the journal entries related to current tax
Address problems anticipated after entry mode : Select preferred entry mode (s) for Automobile investment in Singapore from USA,

Reviews

len3187246

7/28/2022 10:45:11 PM

How to connect to an Oracle server from a C++ program. How to write and execute SQL queries in a C++ program. Submission: Your submission will be a single text-based .cpp file including your C++ program for the Database Application lab. L07_ID_LASTNAME.cpp Your submission needs to be commented. Lab Instruction: Connect to Oracle from Visual Studio C++

Write a Review

Database Management System Questions & Answers

  Create database tables using libreoffice base

COMR2002 BUSINESS INFORMATION SYSTEMS DATABASE APPLICATION ASSIGNMENT. Create database tables using LibreOffice Base

  Examine the cannibalization strategy

Compare and contrast the DYB and GYB strategies in terms of the ability to sustain a business in the marketplace over the long term, to be competitive against

  Develop a project time line

Identify the key tasks required for implementation, including time and resource requirements - Define the team required for implementation of the ECM and data

  Whats the difference between a filter and a query

Whats the difference between a filter and a query

  Determine the data requirements for the oracle database

Your company has a Microsoft Access Contacts database. Your company wants to create an in-house Oracle version of this database.

  Contents of the product table

To list all the contents of the PRODUCT table, you would use and When you issue the DELETE FROM tablename command without specifying a where condition

  Provide the sql code that inserts data into all of the table

Provide the SQL code that inserts data into all of the tables

  Explain primary manner in which chosen method is use in dbms

Select one of transaction management or concurrency control methods, and explain primary manner in which chosen method is used in database management systems.

  Explain the merits and demerits of dbms-provided security

write a 200- to 300-word short-answer response for the followingdescribe the advantages and disadvantages of

  Describe how you created the conceptual and process

Describe how you created the conceptual and process view for all four (4) diagrams. In the description, be sure to provide a justification for each key decision in the design.

  Develop the below queries using professional principles

Design and develop the below queries using professional principles and standards:A set of SQL Statements that returns all rows and all data for each table in your database.Two SQL Statements that return a subset of columns and a subset of rows using ..

  Job support activity cost pools

Compute the activity rates for the Painting and Job Support activity cost pools by filling in the table below. Round off all calculations to the nearest whole cent - Prepare an action analysis report in good form of a job that involves painting 71 ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd