Sei sulla pagina 1di 3

#include <iostream> #include <occi.h> #include <stdio.

h> using namespace std; using namespace oracle::occi; class OracleConnection { private: string userName ; string password ; string database ; public: Environment *env; Connection *conn; OracleConnection(); ~OracleConnection(); }; OracleConnection::OracleConnection():userName("e684315"),password("30071991"),da tabase("oraconn") { env=Environment::createEnvironment(Environment::DEFAULT); conn=env->createConnection(userName,password,database); cout << "OCCI Environment and Connection Created " << endl; } OracleConnection::~OracleConnection() { conn->commit(); cout << "Terminating the Connection and Environment" << endl; env->terminateConnection(conn); Environment::terminateEnvironment(env); } class postplan { Statement *stmt; public: void addpostplan() { OracleConnection aConnection; stmt=aConnection.conn->createStatement(); int c1, c2, c3, c5, c6; string c4; cout<<endl; cout<<endl; cout<<'\t'<<"Enter planid : "; cin>>c1; cout<<'\t'<<"Enter speed : "; cin>>c2; cout<<'\t'<<"Enter rate : "; cin>>c3; cout<<'\t'<<"Enter plan_type : "; cin>>c4; cout<<'\t'<<"Enter instr_cost : "; cin>>c5; cout<<'\t'<<"Enter wired_inst_cst : "; cin>>c6; cout<<endl; cout<<endl; stmt->setSQL("insert into Postpaid_plan values(:1, :2, :3, :4, :5, :6)");

stmt->setInt(1,c1); stmt->setInt(2,c2); stmt->setInt(3,c3); stmt->setString(4,c4); stmt->setInt(5,c5); stmt->setInt(6,c6); int nFlag=stmt->executeUpdate(); aConnection.conn->terminateStatement(stmt); cout<<'\t'<<"--------------------Insert successful-----------------------"<<endl ; cout<<endl; cout<<endl; } void view() { OracleConnection aConnection; stmt=aConnection.conn->createStatement(); int c1,c2,c3,c5,c6; string c4; int cid; cout<<"Enter plan id:"<<endl; cin>>cid; Statement *stmt =aConnection.conn->createStatement("SELECT * FROM postpaid_plan WHERE plan_id= :1"); cout << "Selecting Records from Table " << endl; stmt->setInt(1, cid); ResultSet *rs = stmt->executeQuery(); //Selecting Records from Table rs->next(); c1 = rs->getInt(1); c2 = rs->getInt(2); c3 = rs->getInt(3); c4 = rs->getString(4); c5 = rs->getInt(5); c6 = rs->getInt(6); cout cout cout cout cout cout

//get the 2'nd value

//get the 3'nd value <<"Plan ID :" << c1 << endl; //Print the 1'nd value <<"Speed :" << c2 << endl; //Print the 2'nd value <<"Rate :" << c3 << endl; <<"Plan_type :" << c4 << endl; <<"Instr_cost :" << c5 << endl; <<"Wired_inst_cost:" << c6 << endl;

aConnection.conn->terminateStatement(stmt); } }; int main() { int ans; postplan post; cout<<"Enter your choice:"<<endl; cout<<"1. View Postpaid Plan."<<endl; cout<<"2. Update Postpaid Plan."<<endl;

cout<<"3. Add Postpaid Plan."<<endl; cout<<"4. Delete Postpaid Plan."<<endl; cout<<"......"<<endl; cin>>ans; switch(ans) { case 1: { post.view(); break;} case 2: { post.Update(); break;} case 3: { post.addpostplan(); break;} case 4: { post.deleteplan(); break;} } return 0; }

Potrebbero piacerti anche