技术来源于网络
但网络上的都不怎么完整,总有点小问题,现完整总结一下
1,到oracle官网上下载对于的客户端版本http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html
2,下载occi库,配置vc++环境
3,基本运行仅需要如下几个库文件即可(oci.dll,oraocci10.dll,oraociei10.dll),其他文件看着办
4,vc++代码如下(难点在于连接字符串)
char szUser[]="openlab";
char szPasswd[]="admin";
char szSid[]="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.97)(PORT=1521))/
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyDb)))";
Statement * localStatement=NULL;
ResultSet * rs = NULL;
ResultSet::Status localStatus;
string localStr2;
//链接环境
try
{
m_Env = Environment::createEnvironment();
if( m_Env==NULL )
{
OutputDebugString( "createEnvironment error" );
return -1;
}
m_Conn=m_Env->createConnection(szUser,szPasswd,szSid);
if(m_Conn==NULL)
{
Environment::terminateEnvironment(m_Env);
OutputDebugString( "createConnection error" );
return -1;
}
}
catch(SQLException &e)
{
OutputDebugString( "error" );
OutputDebugString(e.getMessage().data());
goto DoEnd;
}