4,011
社区成员
发帖
与我相关
我的任务
分享
//读数据库中的图片出来
try{
int n = 1;
Blob tmpBlob;
int blobLen;
stmt = conn->createStatement("select imagedata from image where id = :1 for update");
stmt->setInt(1, n);
ResultSet* rs = stmt->executeQuery();
rs->next();
tmpBlob = rs->getBlob(1);
blobLen = tmpBlob.length();
imageBuffer = new BYTE[blobLen];
tmpBlob.read(blobLen,imageBuffer,blobLen,1);
CFile fpWrite;
CFileException e;
fpWrite.Open("2.jpg",CFile::modeWrite | CFile::modeCreate,&e);
fpWrite.Write(imageBuffer,blobLen);
tmpBlob.close();
stmt->closeResultSet(rs);
conn->terminateStatement(stmt);
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
fpWrite.Close();
//释放空间
if(imageBuffer!=NULL)
delete []imageBuffer;
}
catch(SQLException ex){
cout<<ex.getErrorCode()<<endl;
cout<<ex.getMessage()<<endl;
return 0;
}
你好,把数据写到数据库中已经解决了~!能否再帮看下读呢,读的时候走到tmpBlob.close();的时候就抛出一个ORA-22289:无法在未打开的文件或LOB上执行操作的异常,请问该如何解决呢?谢谢