2012-06-07 67 views
2

我想用以下代碼在oracle中爲DATE執行數組提取。它編譯好,並正確導出所有其他數據類型,除了DATE類型。該程序說「ora-32146無法在無效日期執行操作」。我錯在哪裏? SetDataBuffer for DATE

任何人都可以看到我錯在哪裏?

Statement *stmt = conn->createStatement("SELECT AGE,CASH2, BIRTHDATE from myTable2"); /*, CASH1, CASH2, BIRTHDATE*/ 
    //stmt->setMaxParamSize(1,sizeof(Number)); 
    ResultSet *rs=stmt->executeQuery(); 
    string myName[400]; 
    int myAge[400]; 
    double myCash1[400]; 
    double myCash2[400]; 
    oracle::occi::Date myBirthDate[400]; 

    //rs->setDataBuffer(1,myName,OCCI_SQLT_STR,sizeof(string)); 
    rs->setDataBuffer(1,myAge,OCCIINT,sizeof(int)); 
    rs->setDataBuffer(2, myCash2, OCCIBDOUBLE, sizeof(double),NULL); 
    rs->setDataBuffer(3, myBirthDate,OCCI_SQLT_DATE, sizeof(oracle::occi::Date),NULL); 

    while (rs->next(200)==ResultSet::DATA_AVAILABLE) 
    { 
     //cout << "Exporting batch..." << endl; 
     for(size_t i=0;i<rs->getNumArrayRows();i++) 
     { 
      //cout << myName[i] << endl; 
      cout << myAge[i] << endl; 
      //cout << myCash1[i] << endl; 
      cout << myCash2[i] << endl; 
      int y; 
      unsigned int m,d,h,mm,s; 
      myBirthDate[i].getDate(y,m,d,h,mm,s); 
      cout << y <<"-"<<m<<"-"<<s << endl; 
     } 
    } 

回答

2

想通了。

使用rs-> setDataBuffer(3,myBirthDate,OCCI_SQLT_DAT,7,NULL);

工作沒問題。

OCCI沒有好的文件...