try
{
ResultSet *pRS = pStmt->executeQuery("select* from serverinfo");
if (pRS)
{
cout << "executeQuery success." << endl;
while (pRS->next())
{
string str = pRS->getString(1);
cout << str << endl;
}
pStmt->closeResultSet(pRS);
}
}
catch (SQLException ex)
{
string errMsg;
// errMsg = ex.getMessage();
errMsg = ex.what();
cout << "executeQuery failed: " << errMsg << endl;
}上面的代码,只要调用getMessage函数(当然是异常发生了之后,比如查询一张不存在的表),必定出现错误,dbgheap.c 1132行:
_CrtIsValidHeapPointer(pUserData)
如果调用what则没事。

解决方案 »

  1.   

    The message provided by sqlException.getMessage() is "batch bla bla something" but the correct Exception message to parse is sqlException.getNextException().getMessage()
      

  2.   

    可是oracle官方例子也是这样写的:
    catch (SQLException &ex)
      {
          cout << "Error running demo : " << ex.getMessage() << endl;
      }区别是它用SQLException &ex而我用SQLException ex,我改成它那样也仍然错误。
    这个例子的文件名叫:storedproc.cpp,不过好像是oracle9的。
      

  3.   

    而且,在我的OCCI里面(安装oracle10后得到的),SQLException没有getNextException函数,SQLException的定义如下:class SQLException : public OCCI_STD_NAMESPACE::exception
    {
     public:  virtual int getErrorCode() const;
      
      virtual OCCI_STD_NAMESPACE::string getMessage() const;  const char *what() const throw();  virtual void setErrorCtx(void *ctx);
      
      SQLException();  SQLException(const SQLException &e);  void operator=(const SQLException &other);  virtual ~SQLException() throw();  virtual int getXAErrorCode(const OCCI_STD_NAMESPACE::string& dbname) const;
      
      virtual UString getUStringMessage() const;  virtual OCCI_STD_NAMESPACE::string getNLSMessage(Environment *env) const;
      
      virtual UString getNLSUStringMessage(Environment *env) const; private:  Ptr<SQLExceptionImpl> ptr_;
      SQLException(SQLExceptionImpl *ptr);
      friend SQLException SQLExceptionCreate(int errorCode);
      friend SQLException SQLExceptionCreate(dvoid *handle,
      int handleType);};