第一步:oracle版本为32位,64位应用程序连接,因此需要64位的ODBC驱动。下载32位对应的64位驱动。主要包括两个文件,如图所示。将两个文件夹中的文件放入同一个文件夹下。之后,点击odbc_install.exe,通过尝试管理员身份运行,也可以通过cmd运行,主要目的是为了创建驱动。
第二步:在 控制面板\系统和安全\管理工具 中找到 ODBC 数据源(64位)应用程序,运行。
点击添加,选择对应的oracle驱动程序即可。在这里可以测试,连接是否成功。
第三步:生成对应的连接字符串,由于驱动程序的不同,连接字符串也不同。这里采取了前面博文的方法。
https://blog.csdn.net/weixin_41597991/article/details/90517612 如何利用ADO生成连接字符串
第四步:程序实现:
#include "stdafx.h"
#include "stdafx.h"
#include <iostream>
#include "afx.h"
#include<iostream>
#import "C:\\Program Files\\Common Files\\system\\ado\\msado15.dll" no_namespace rename("EOF", "adoEOF")
using namespace std;
int main()
{
CoInitialize(NULL);
_ConnectionPtr m_pConnection;//实例化
_CommandPtr m_pCommand;
_RecordsetPtr m_pRecordset;
m_pConnection.CreateInstance(__uuidof(Connection));
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
_bstr_t strConnect = "DRIVER={Oracle in ODBC};SERVER=ORCL;UID=sfcl;PWD=LNB;DBQ=ORCL;DBA=W;APA=T;EXC=F;XSM=Default;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BNF=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=Me;CSR=F;FWC=F;FBS=60000;TLO=O;MLD=0;ODA=F;STE=F;TSZ=8192;AST=FLOAT;";
HRESULT hr = m_pConnection->Open(strConnect, "", "", adModeUnknown);
// 执行命令
m_pCommand.CreateInstance(__uuidof(Command));
m_pCommand->ActiveConnection = m_pConnection;
CString No1 = "select * from LNBTEST";
_variant_t temp1_2 = No1;
//先关闭记录集
//使用这种方法可以实现记录集的更新
m_pRecordset->Open(temp1_2,
m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
CString no = "3";
CString x_min = "jjj";
_variant_t temp2 = no;
_variant_t temp3 = x_min;
m_pRecordset->AddNew();///添加新记录
m_pRecordset->PutCollect(_variant_t("ID"), temp2); //添加
m_pRecordset->PutCollect(_variant_t("PassWord"), temp3);
m_pRecordset->Update();
//关闭连接
if (m_pConnection->State) {
m_pRecordset->Close();
m_pRecordset = NULL;
m_pConnection->Close();
m_pConnection = NULL;
CoUninitialize();
}
}
catch (_com_error &e) {
//MessageBox(NULL,(CATUnicodeString)((string)e.Description()),L"警告",MB_OKCANCEL);
cout << e.Description() << endl;;
}
return 0;
}
该实现主要是为了实现在catia二次开发中,将数据导入数据库,和web端进行交互。。。