Oracle数据库的实现main():
#include "CDBOperation.h"
#include <iostream>
#include <afx.h>
#include <afxinet.h>
#include <afxwin.h>
using namespace std;
void main(){
CDBOperation dbObject;
bool bConn = dbObject.ConnToDB();
if (true == bConn)
{
AfxMessageBox("connection success \0");
// ::MessageBox(NULL, "abc!",_T("attention"), MB_OKCANCEL == IDOK);
// MessageBox("连接数据库出现错误\0",0,0);
return;
}
//查询
_RecordsetPtr pRst;
char sql[255] = {0};
strcpy(sql, " select * from boss_test_table2 where rownum = 1 ");
pRst = dbOper.ExecuteWithResSQL(sql);
if (NULL == pRst)
{
MessageBox(NULL,sql,"Info",4);
return;
}
if (pRst->adoEOF)
{
pRst->Close();
AfxMessageBox("There is no records in this table\0");
MessageBox(NULL,"There is no records in this table\0",0,0);
return;
}
_variant_t vSno, vName;
while (!pRst->adoEOF)
{
//pRst->MoveFirst(); //记录集指针移动到查询结果集的前面
vSno = pRst->GetCollect(_variant_t("U_NUMBER"));
vName = pRst->GetCollect(_variant_t("USERS_NAME"));
MessageBox(NULL,(LPCTSTR)(_bstr_t)vSno,0,0);
pRst->MoveNext();
}
strcpy(sql, "insert into boss_test_table2 (u_number, users_name, users_phone, status, customno_id) values ('0001', 'C+TTT+', '13999000000', 2, 'BPPPPPPPPPP')");
pRst = dbOper.ExecuteWithResSQL(sql);
if (NULL != pRst)
{
AfxMessageBox(_T("插入数据成功\n"));
}
//执行删除语句
sprintf(sql, "delete boss_test_table2 where u_number = '%s'", "009");
pRst = dbOper.ExecuteWithResSQL(sql);
if (NULL != pRst)
{
MessageBox(NULL,_T("删除数据成功\0"),0,0);
}
//执行更新语句
sprintf(sql, "update boss_test_table2 set users_name = '%s' ", "C++反人类、MFC反社会");
pRst = dbOper.ExecuteWithResSQL(sql);
if (NULL != pRst)
{
MessageBox(NULL,_T("更新数据成功\0"),0,0);
}
}
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
