怎样向Oracle的Blob字段中添加bmp图片
这段是我参考一个文档写的,添加不进去,请问问题在哪,急,在线等待,我是新手,资源分也不多,谢谢各位大哥大姐了。
char* procsql = "INSERT INTO T_SOC_CS_TOPO_GRAPH(GraphID,GraphName,GraphTypeID,Graph,Format) VALUES (:1,:2,:3,:4,:5)";
m_pstmt->setSQL(procsql);
Blob blob(m_pmysql);
blob.setEmpty();
m_pstmt->setInt(1,2);
m_pstmt->setString(2,"name");
m_pstmt->setInt(3,3);
m_pstmt->setBlob(4,blob);
m_pstmt->setString(5,"format");
m_pstmt->executeUpdate();
m_pmysql->commit();
string sqlQuery = "SELECT Graph FROM T_SOC_CS_TOPO_GRAPH where GraphID=1 FOR UPDATE";
m_pstmt->setSQL(sqlQuery);
ResultSet *rs = m_pstmt->executeQuery();
while(rs->next())
{
Blob blob=rs->getBlob(1);
unsigned int blobLen=blob.length();
unsigned int offset=1;
fstream infile;
infile.open("IAD.bmp",std::ios::binary | ios::in);
if (!infile.is_open())
{
return -1;
}
infile.seekp(0L ,ios::end);
int nlen = infile.tellp();
char* buf = new char[nlen + 1];
infile.seekp(0,ios::beg);
infile.read(buf, nlen);
infile.close();
Stream* strm=blob.getStream();
strm->writeBuffer(buf, nlen);
blob.closeStream (strm);
delete[] buf;
}