欢迎来到天天文库
浏览记录
ID:11292940
大小:26.93 KB
页数:5页
时间:2018-07-11
《在vc6中使用ado读取oracle中的blob字段》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、在VC6中使用ADO读取Oracle中的BLOB字段 今天尝试将存储于Oracle(版本:9.0.1.1.1)中BLOB字段里的图像文件读出来,文件量很小,不到10K。使用vc6+ADO,使用控制台程序初步尝试如下:::CoInitialize(NULL); //初始化OLE/COM库环境_ConnectionPtr m_pConn;try{ HRESULT hr = m_pConn.CreateInstance("ADODB.Connection"); if(FAILED(hr))
2、{ cout<<"Create ADO Connection failed"<3、rd = "stuinfo"; hr = m_pConn->Open((_bstr_t)oracleConnectionString, (_bstr_t)oracleUserID, (_bstr_t)oraclePassword, adModeUnknown); if (FAILED(hr)) { cout<<"Can not connect to database"<4、ut<<"Connect to database successfully!"<5、LED(hr)) { cout<<"Create ADO Recordset failed"<6、set->Open(bstrSQL, (IDispatch*)m_pConn, adOpenDynamic, adLockOptimistic, adCmdText); if (FAILED(hr)) { cout<<"Open ADO Recordset failed"<7、dl; exit(0);}long lDataSize = m_pRecordset->GetFields()->GetItem("stupic")->ActualSize;cout<<"BLOB length is "< 0){ _variant_t varBLOB; varBLOB = m_pRecordset->GetFields()->GetItem("stupic")->GetChunk(lDataSize); 8、 //判断数据类型是否正确 if(varBLOB.vt == (VT_ARRAY 9、 VT_UI1)) { BYTE *pBuf = NULL; //得到指向数据的指针 SafeArrayAccessData(varBLOB.parray, (void **)&pBuf); /**//***这里是对pBuf数据的处理***/
3、rd = "stuinfo"; hr = m_pConn->Open((_bstr_t)oracleConnectionString, (_bstr_t)oracleUserID, (_bstr_t)oraclePassword, adModeUnknown); if (FAILED(hr)) { cout<<"Can not connect to database"<4、ut<<"Connect to database successfully!"<5、LED(hr)) { cout<<"Create ADO Recordset failed"<6、set->Open(bstrSQL, (IDispatch*)m_pConn, adOpenDynamic, adLockOptimistic, adCmdText); if (FAILED(hr)) { cout<<"Open ADO Recordset failed"<7、dl; exit(0);}long lDataSize = m_pRecordset->GetFields()->GetItem("stupic")->ActualSize;cout<<"BLOB length is "< 0){ _variant_t varBLOB; varBLOB = m_pRecordset->GetFields()->GetItem("stupic")->GetChunk(lDataSize); 8、 //判断数据类型是否正确 if(varBLOB.vt == (VT_ARRAY 9、 VT_UI1)) { BYTE *pBuf = NULL; //得到指向数据的指针 SafeArrayAccessData(varBLOB.parray, (void **)&pBuf); /**//***这里是对pBuf数据的处理***/
4、ut<<"Connect to database successfully!"<5、LED(hr)) { cout<<"Create ADO Recordset failed"<6、set->Open(bstrSQL, (IDispatch*)m_pConn, adOpenDynamic, adLockOptimistic, adCmdText); if (FAILED(hr)) { cout<<"Open ADO Recordset failed"<7、dl; exit(0);}long lDataSize = m_pRecordset->GetFields()->GetItem("stupic")->ActualSize;cout<<"BLOB length is "< 0){ _variant_t varBLOB; varBLOB = m_pRecordset->GetFields()->GetItem("stupic")->GetChunk(lDataSize); 8、 //判断数据类型是否正确 if(varBLOB.vt == (VT_ARRAY 9、 VT_UI1)) { BYTE *pBuf = NULL; //得到指向数据的指针 SafeArrayAccessData(varBLOB.parray, (void **)&pBuf); /**//***这里是对pBuf数据的处理***/
5、LED(hr)) { cout<<"Create ADO Recordset failed"<6、set->Open(bstrSQL, (IDispatch*)m_pConn, adOpenDynamic, adLockOptimistic, adCmdText); if (FAILED(hr)) { cout<<"Open ADO Recordset failed"<7、dl; exit(0);}long lDataSize = m_pRecordset->GetFields()->GetItem("stupic")->ActualSize;cout<<"BLOB length is "< 0){ _variant_t varBLOB; varBLOB = m_pRecordset->GetFields()->GetItem("stupic")->GetChunk(lDataSize); 8、 //判断数据类型是否正确 if(varBLOB.vt == (VT_ARRAY 9、 VT_UI1)) { BYTE *pBuf = NULL; //得到指向数据的指针 SafeArrayAccessData(varBLOB.parray, (void **)&pBuf); /**//***这里是对pBuf数据的处理***/
6、set->Open(bstrSQL, (IDispatch*)m_pConn, adOpenDynamic, adLockOptimistic, adCmdText); if (FAILED(hr)) { cout<<"Open ADO Recordset failed"<7、dl; exit(0);}long lDataSize = m_pRecordset->GetFields()->GetItem("stupic")->ActualSize;cout<<"BLOB length is "< 0){ _variant_t varBLOB; varBLOB = m_pRecordset->GetFields()->GetItem("stupic")->GetChunk(lDataSize); 8、 //判断数据类型是否正确 if(varBLOB.vt == (VT_ARRAY 9、 VT_UI1)) { BYTE *pBuf = NULL; //得到指向数据的指针 SafeArrayAccessData(varBLOB.parray, (void **)&pBuf); /**//***这里是对pBuf数据的处理***/
7、dl; exit(0);}long lDataSize = m_pRecordset->GetFields()->GetItem("stupic")->ActualSize;cout<<"BLOB length is "< 0){ _variant_t varBLOB; varBLOB = m_pRecordset->GetFields()->GetItem("stupic")->GetChunk(lDataSize);
8、 //判断数据类型是否正确 if(varBLOB.vt == (VT_ARRAY
9、 VT_UI1)) { BYTE *pBuf = NULL; //得到指向数据的指针 SafeArrayAccessData(varBLOB.parray, (void **)&pBuf); /**//***这里是对pBuf数据的处理***/
此文档下载收益归作者所有