typedef char STD_FIELD_VALUE[FETCH_COUNT][MAX_FIELD_LEN]; #pragma pack(1) typedef struct { unsigned int iRecRowNum; //有多少行记录 STD_FIELD_VALUE *pStdValueBuff; }RECORD_DATA; |
void ExecuteArrayUpdate(string sSql,int iColNum,int iRowNum,RECORD_DATA *pFieldValue,ub2 (*pElemLen)[FETCH_COUNT]) throw(SQLException) { int iArray[FETCH_COUNT]; try { if(m_pStmt==NULL) m_pStmt = m_pOcciConn->createStatement(); m_pStmt->setSQL(sSql); for(int i=0;i<iColNum;i++) { m_pStmt->setDataBuffer(i+1,pFieldValue->pStdValueBuff[i],OCCI_SQLT_STR, MAX_FIELD_LEN,pElemLen[i],(sb2*)NULL,(ub2*)NULL); } m_pStmt->executeArrayUpdate(iRowNum); } catch()...... } |
#include <iostream> #include <occi.h> using namespace std; using namespace oracle::occi; #define ARRAY_SIZE 10 int main() { Environment *pEnv = NULL; Connection *pCon = NULL; Statement *pStmt = NULL; try { pEnv = Environment::createEnvironment ((Environment::Mode)(Environment::OBJECT|Environment::THREADED_UNMUTEXED)); pCon = pEnv->createConnection("xxxx", "xxxxx", "xxxxxxxx"); pStmt = pCon->createStatement("insert into table(code) values (:1);"); } catch(SQLException &ex) { cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; return -1; } int pServID[ARRAY_SIZE]; ub2 pLen[ARRAY_SIZE]; for(int i = 0; i < ARRAY_SIZE; ++i) { pServID[i] =i*2; pLen[i] = sizeof(pServID[i]); } try { pStmt->setDataBuffer(1,pServID, OCCIINT, sizeof(int), pLen,(sb2*)NULL,(ub2*)NULL); //ORA-32109: invalid column or parameter position pStmt->executeArrayUpdate(ARRAY_SIZE); pCon->commit(); } catch(SQLException &ex) { cout<<"Error number: "<< ex.getErrorCode() << endl; cout<<ex.getMessage() << endl; ///资源释放 //delete[] pServID; //pServID = NULL; //delete[] pLen; //pLen = NULL; pCon->terminateStatement(pStmt); pEnv->terminateConnection(pCon); Environment::terminateEnvironment (pEnv); return -1; } //delete[] pServID; //pServID = NULL; //delete[] pLen; //pLen = NULL; pCon->terminateStatement(pStmt); pEnv->terminateConnection(pCon); Environment::terminateEnvironment (pEnv); return 0; } |
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |