+1835 731 5494 Email: instantessays65@gmail.com

C++/Database Lab

$12.99

C++/Database Lab Part A: Purpose: This laboratory provides some experience working with the C++ programming language that has an SQL query and SQL update embedded in it. Procedure: Follow the instructions below. Be sure to load the C++ to ProQueryExample code presented in the Appendix A below. In your ProQueryExample.cpp source file, modify the source code so that it changes the customer balance of Streaming Direct from $210.40 to $337.26. Rerun the query in step 3 above. Modify the source to return the balance of Streaming Direct to $210.40. Rerun the query in step 3 above. Print out a copy of your output. Submit a cover sheet, a copy of your output, and the source code that you used to obtain it. Follow any additional instructions that your instructor may give you. Appendix A /* * Name: ProQueryExample.cpp * * Description * This source code displays a join of the invoice and * customer tables. In addition this source code updates the Streaming * Direct customer name to Direct Sports and then returns the name back * to Streaming Direct. * * Remarks: * Author Date Comment * Mike Lukens 08/08/2008 initial code * */ #include #include #include using namespace oracle::occi; using namespace std; class occiIntf { public: //constructor occiIntf ( string login, string password, string dbStr ) { //setup the environment which Oracle requires environ = Environment::createEnvironment ( Environment::DEFAULT ); try { //create a connection to the database connect = environ->createConnection ( login, password, dbStr ); } catch ( SQLException excpt ) { cout terminateConnection ( connect ); Environment::terminateEnvironment ( environ ); } //update a field void updateField ( string name, string id ) { //change the customer name to/from Direct Sports in CUSTOMER table string sqlStatmt = “UPDATE customer SET cust_name = 😡 WHERE cust_id = :y”; statmt = connect->createStatement ( sqlStatmt ); try { //substitute the customer name and id into the SQL statement statmt->setString ( 1, name ); statmt->setString ( 2, id ); statmt->executeUpdate (); cout terminateStatement ( statmt ); } //display the invoice number, date, and customer name void displayAllRows ( ) { //create the SQL statement string sqlStatmt = “SELECT invoice_num, invoice_date, cust_name FROM invoice, customer WHERE invoice.cust_id = customer.cust_id”; //instantiate the statement object from our connection object //using the SQL string to initialize the statement statmt = connect->createStatement ( sqlStatmt ); try { //execute the query and point to the result set //in order to loop through the returned data. ResultSet *resSet = statmt->executeQuery ( ); //display the column headers cout next ( ) ) { //extract each attribute value which is a string cout getString ( 1 ) getString ( 2 ) getString ( 3 ) closeResultSet ( resSet ); } catch ( SQLException excpt ) { cout terminateStatement ( statmt ); } private: //variables required by OCCI Environment * environ; Connection * connect; Statement * statmt; }; //end of occiIntf class void main ( ) { string dbStr = “ECET450”; string login; string password; cout > login; cout > password; system ( “CLS” ); //clear the screen cout displayAllRows ( ); cout updateField ( “Direct Sports” , “1193” ); cout displayAllRows ( ); cout updateField ( “Streaming Direct” , “1193” ); cout displayAllRows ( ); delete database; cout #include #include using namespace oracle::occi; using namespace std; class occiIntf { public: //constructor occiIntf ( string login, string password, string dbStr ) { //create an environment which Oracle requires environ = Environment::createEnvironment ( Environment::DEFAULT ); try { //create a connection to the database connect = environ->createConnection ( login, password, dbStr );

Reviews

There are no reviews yet.

Be the first to review “C++/Database Lab”

Your email address will not be published. Required fields are marked *