进行连接本地ORACLE数据库m_pConnection->ConnectionString =
"Provider=OraOLEDB.ORACLE.1;
Data Source=jiey;
User Id=system;
Password=manager;";
m_pConnection->Open( "", "", "",adConnectUnspecified );
然后打开数据表m_pRecordset->Open("SELECT * FROM table", m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
再循环插入数据到表中
for (int i=0 ; i<1000; i++)
{m_pRecordset->AddNew();
m_pRecordset->PutCollect("NAME", _variant_t(name));
m_pRecordset->PutCollect("SEX", _variant_t(sex));
m_pRecordset->PutCollect("SALARY", atof(temp1));
m_pRecordset->PutCollect("ADDRESS", _variant_t(temp2));
m_pRecordset->Update();
}
就这样整个执行完要6秒钟,由于我的实时性要很强,有没有办法可以提高速度?
"Provider=OraOLEDB.ORACLE.1;
Data Source=jiey;
User Id=system;
Password=manager;";
m_pConnection->Open( "", "", "",adConnectUnspecified );
然后打开数据表m_pRecordset->Open("SELECT * FROM table", m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
再循环插入数据到表中
for (int i=0 ; i<1000; i++)
{m_pRecordset->AddNew();
m_pRecordset->PutCollect("NAME", _variant_t(name));
m_pRecordset->PutCollect("SEX", _variant_t(sex));
m_pRecordset->PutCollect("SALARY", atof(temp1));
m_pRecordset->PutCollect("ADDRESS", _variant_t(temp2));
m_pRecordset->Update();
}
就这样整个执行完要6秒钟,由于我的实时性要很强,有没有办法可以提高速度?
因为每插入一条记录,MFC都要花一定的时间去构建一条插入语句,效果差
不知道可不可以进行批量插入
"Provider=OraOLEDB.ORACLE.1;
Data Source=jiey;
User Id=system;
Password=manager;";
m_pConnection->Open( "", "", "",adConnectUnspecified );这部分整个运行期只做一次,连接是很费时间的,不要总是open如果不需要查看数据就不要m_pRecordset->Open了
直接用m_pConnection执行SQL语句插入
我想这样会快很多
adOpenDynamic,
adLockBatchOptimistic,
adCmdText);
使用批操作
先插入到本地缓存
然后再循环后提交
m_pRecordset->UpdateBatch(adAffectAll);
这样效率会提高很多 非常明显
m_pRecordset->PutCollect("NAME", _variant_t(name));
m_pRecordset->PutCollect("SEX", _variant_t(sex));
m_pRecordset->PutCollect("SALARY", atof(temp1));
m_pRecordset->PutCollect("ADDRESS", _variant_t(temp2));
m_pRecordset->Update();
插入到本地缓存,待缓存1000后执行以上m_pRecordset->UpdateBatch(adAffectAll);提交?
在线等待,给分,结帐……
OCI(oracle C interface)速度要比你这样连块很多
OCCI(oracle C++ interface)在9i中才有
可以试试,不过OCI过于难还是建议用OLE DB,MFC也支持--------------
May you succeed!
----------------
OCI Oracle Call Interface
OCCI Oracle C++ Call Interface
还有个问题,ADO中如何执行删除一个表中的所有记录或者调用一个写好的删除过程(ORACLE中)char strdelete[100];
strcpy(strdelete,"CALL delete_table()"); //delete_table是一个存储过程
int rtcode;
rtcode=(NULL,(SQLCHAR*)strdelete,SQL_NTS);
最后返回rtcode为不成功,请高手赐教!
"Provider=OraOLEDB.ORACLE.1;
Data Source=jiey;
User Id=system;
Password=manager;";
中的OraOLEDB.ORACLE.1为什么在局域网的机子上运行提示错误。 (在ORACLE9I服务器上运行正常),局域网上那台机器没装ORACLE ,是不是就没提供此驱动? 急切,盼高手回复
你删除一个表的所有记录用truncate table 表名
(大多数据库都支持这个,操作很快)
用_command对象执行
你试试不要在程序中连接
在ODBC中试一下
这个不好判断