//存储过程
create or replace procedure ADDDDD(
pid in number,
pname in VARCHAR2
) is
begin
INSERT INTO studentto VALUES(pid,pname);
end ADDDDD;
#include #include #include #define LINUXOCCI #include #include #include #include #include using namespace std; using namespace oracle::occi; class TestCallPRO { public: TestCallPRO(std::string userName,std::string passWD,std::string serverName);//参数初始化 ~TestCallPRO(); void LinkOnOracle();//链接数据库 void LinkOffOracle();//断开数据库的链接 void SpliceSQL(std::list &cValues); //拼接SQL语句(insert 的存储过程) void CValuesToList(char* &p1,char *&p2,std::list &cValues); //参数入栈 void ExecuteSQlProc(std::list &cValues);//调用执行存储过程 protected: Environment *m_env; Connection *m_conn; Statement *m_pstmt; std::string m_userName;//数据库用户名 std::string m_passWD;//用户密码 std::string m_serverName; //格式: :/ }; TestCallPRO::TestCallPRO(std::string userName,std::string passWD,std::string serverName) { m_env = NULL; m_conn = NULL; m_pstmt = NULL; m_userName = userName; m_passWD = passWD; m_serverName = serverName; } void TestCallPRO::LinkOnOracle() { m_env=Environment::createEnvironment();//创建数据库连接对象 m_conn = m_env->createConnection(m_userName,m_passWD,m_serverName);//Link } void TestCallPRO::LinkOffOracle() { m_env->terminateConnection(m_conn); Environment::terminateEnvironment(m_env); } void TestCallPRO::SpliceSQL(std::list &cValues) { std::string astrSQL = ""; astrSQL = "call "; astrSQL += "ADDDDD"; astrSQL += "("; char suu[2] ={ 'x','\0'}; std::list::iterator loIter = cValues.begin(); for(; loIter != cValues.end(); loIter++) { std::string str = ""; str = &suu[0]; astrSQL += ":"; astrSQL += str; astrSQL += ","; ++ suu[0]; } if(astrSQL[astrSQL.length() - 1] == '(') { astrSQL[astrSQL.length() - 1] = ';'; } else { astrSQL[astrSQL.length() - 1 ] = ')'; } m_pstmt = m_conn->createStatement();//执行非查询语句 不需要传递SQL语句 m_pstmt->setSQL(astrSQL); } void TestCallPRO::CValuesToList(char* &p1,char *&p2,std::list &cValues) { cValues.push_back(p1); cValues.push_back(p2); } void TestCallPRO::ExecuteSQlProc(std::list &cValues) { m_pstmt->setAutoCommit(false); m_pstmt->setMaxParamSize(1,sizeof(int)); m_pstmt->setMaxParamSize(2,sizeof(string)); char *p1 = NULL; int itemp = 0; try { std::list::iterator iter = cValues.begin(); itemp = atoi((*iter)); cout<setInt(1, itemp); cout<setString(2, p1); } catch(SQLException ex) { cout<executeUpdate();//执行非查询语句 m_conn->commit(); cout< aoStoParam; TestCallPRO testcallPRO("xxxxx","xxxxx","xx.xx.xx.xx:xx/xxxx"); testcallPRO.LinkOnOracle(); testcallPRO.CValuesToList(p1, p2, aoStoParam); testcallPRO.SpliceSQL(aoStoParam); testcallPRO.ExecuteSQlProc(aoStoParam); testcallPRO.LinkOffOracle(); return 0; }