循环绑定参数使用set×××()方法,每循环一次必须使用addIteration()方法再进行下一次循环,直到最后一次。例子如下所示: #include <iostream> #include <occi.h>
using namespace oracle::occi; using namespace std;
int main () {
Environment *env; Connection *conn; Statement *stmt;
string username = "bill"; string password = "bill"; string connstring = "jftest"; string sql;
int isno[2]={21,22},i,iage[2]={18,19}; string csname[2]={"namea","nameb"};
try {
env = Environment::createEnvironment();
conn = env->createConnection(username,password,connstring); stmt = conn->createStatement(); stmt->setAutoCommit(false);
sql = " INSERT INTO student (sno,sname,age) VALUES (:x,:y,:z) ";
m_stmt->setSQL(sql);
m_stmt->setMaxIterations(2);
m_stmt->setMaxParamSize(1,sizeof(int)); m_stmt->setMaxParamSize(2,sizeof(string)); m_stmt->setMaxParamSize(3,sizeof(int)); cout<<"setMaxIterations success !"<<endl;
//cout<<"getMaxIterations = "<<m_stmt->getMaxIterations()<<endl; for (i=0;i<2;i++) {
m_stmt->setInt(1,isno[i]);
m_stmt->setString(2,csname[i]); m_stmt->setInt(3,iage[i]);
//cout <<isno[i]<< " and " << csname[i]<< " and " << iage[i] <<endl;