在c ++中读取大型二进制文件

时间:2014-11-04 16:53:38

标签: c++ oracle

我正在尝试读取大小约为360kb的二进制文件(.dat格式)并将其插入到oracle数据库的blob列中。我面临的问题是我的代码没有插入完整的文件,但只插入文件的一部分。我想知道是否有任何方法来读取大型二进制文件。这个代码适用于小二进制文件...这是我的代码......

#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <occi.h>

using namespace oracle::occi;
using namespace std;


int main () {

Environment *env;
Connection *conn;
Statement *stmt;


env = Environment::createEnvironment (Environment::DEFAULT); 
try{
    conn = env -> createConnection("oracle", "oracle", "xxxxx"); 
    stmt = conn -> createStatement("insert into velodyne(name,info) VALUES(:x,:y)"); 
    stmt -> setInt(1,112);

    streampos size;
    char* memblock;
    ifstream fileIn ("filename", ios::in|ios::binary|ios::ate); 
        if (fileIn.is_open())
            {
                size = fileIn.tellg();
                cout<<"size of the file is:"<< size <<endl;
                memblock = new char [size];
                //cout<<"size of the memblock is:"<< memblock <<endl;
                fileIn.seekg (0, ios::beg);
                fileIn.read (memblock, size);
                fileIn.close(); 
            }

    Bytes *Data = new Bytes((unsigned char*) memblock, size); 

    stmt -> setBytes(2, *Data); 
    stmt -> executeUpdate();
    conn->commit();
    delete[] memblock;
        conn->terminateStatement (stmt);
}
    catch (SQLException ea)
     {
    cout<<ea.what();            
    }

Environment::terminateEnvironment (env);
return 0;
}

0 个答案:

没有答案
相关问题