c++封装odbc类

//DBUtil.h

//By 小E QQ592646022

#include

#include #include #include #include #include using namespace std; class ODBC { private: SQLHANDLE hEnv; SQLHANDLE hDbc; SQLHANDLE hStmt; SQLRETURN retCode; SQLINTEGER retErro; SQLINTEGER rowCount; SQLSMALLINT colCount; bool bState; char* pszUName; char* pszUPassword; char* pszDSN; public: ODBC(); ~ODBC(); bool Connect(); bool Close(); bool IsOpen(); int GetRowCount(){return rowCount;} int GetColCount(){return colCount;} vector ExecuteQueryVector(const char* pszSql); int ExecuteQuery(const char* pszSql); //执行查询 int ExecuteNonQuery(const char* pszSql);//执行非查询(更新或删除) int ExecuteUpdate(const char* pszSql); //执行更新 }; ODBC::ODBC() { bState=false; rowCount=colCount=0; retCode=SQLAllocHandle(SQL_HANDLE_ENV,NULL,&hEnv); if((retCode!=SQL_SUCCESS)&& (retCode != SQL_SUCCESS_WITH_INFO)) { cout<<"Erro AllocHandle"< ODBC::ExecuteQueryVector(const char* pszSql) { vector v; if(pszSql==NULL) return 0; retCode=SQLExecDirect(hStmt,(SQLCHAR*)pszSql,SQL_NTS); if((retCode != SQL_SUCCESS) && (retCode != SQL_SUCCESS_WITH_INFO)) { cout<<"Erro ExecDirect "< using namespace std; int main() { ODBC odbc; odbc.Connect(); vector vv=odbc.ExecuteQueryVector("select * from users"); vector::iterator it; for(it=vv.begin();it!=vv.end();it++) { for(int i=0;i<odbc.GetColCount();i++) { cout<<(*it)[i]<<" "; } cout<<(*it)[6]<<" "<<endl; } //odbc.ExecuteNonQuery("insert into users values('1','abcd',34,'男','2010-8-9','')"); cout<<odbc.ExecuteNonQuery("delete from users where ID='10017'"); return 0; }