// This program tests the user's connection to the Oracle server #include #include using namespace std; // Include the sql communications area: #include void main () { EXEC SQL BEGIN DECLARE SECTION; varchar userid[20]; varchar password[20]; char dbstring[10]; EXEC SQL END DECLARE SECTION; // Prompt user for username and password: cout << "Enter your username: "; cin >> userid.arr; cout << "Enter your password: "; cin >> password.arr; // Connect to the INVESTMENTS database: userid.len = strlen((char *) userid.arr); password.len = strlen((char *) password.arr); strcpy(dbstring, "cp01"); EXEC SQL connect :userid identified by :password using :dbstring; // Check connection is OK if (sqlca.sqlcode != 0) { cout << endl << "Connection failed; check username and password"; cout << endl << "SQL Code is: " << sqlca.sqlcode; cout << endl << "Error message: " << sqlca.sqlerrm.sqlerrmc; cout << endl << endl; } else { cout << endl << "Connect is OK" << endl << endl; // Disconnect from the database: EXEC SQL commit release; } }