C++调用存储过程-创新互联
Long long ago,项目里用的数据库是Oracle,服务用的是ICE,俺也是写过存储过程、发布过ICE服务的猿。
步骤一、使用PLSQL连接Oracle如下图所示,使用PLSQL,输入用户名、密码、Schema连接Oracle成功后打开主界面,在Tables中可以查看所有的数据表,在Packages中查看所有的存储过程申明组成的包,在Package bodies中查看所有的存储过程正文组成的包。当然你可以右键new一个出来。以下是一个简单示例,主要实现对目录的各类操作:增、删、改等功能,C++调用Oracle存储过程,发布成服务。这一小示例,也是很有普遍意义的。现在在这一步,我们主要看一下包PKG_KEYWORD_MANAGE的实现过程。
![](https://images0.cnblogs.com/blog/281401/201407/181907421157763.png)
![](https://images0.cnblogs.com/blog/281401/201407/181907425684691.png)
![](https://images0.cnblogs.com/blog/281401/201407/181907429592404.png)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
::Ice::Int
KeywordMgr::KeywordMgrInterfaceI::AddDir(::Ice::Int userId,
::Ice::Int parentDirId,
const ::KeywordMgr::DirInfoStruct& dirInfo,
::KeywordMgr::ByteSequence& strErrMsg,
const Ice::Current& current)
{
CObjectQueryUtil db; //定义连接类
int dirId = 0;
int isHaveNode = 0;
int isParentExit = 0;
int flag = db.Init(m_strUser, m_strPwd, m_strDBSid);
if (flag == -1)
{
this ->ConvertStringToBytes(strErrMsg, db.GetLastErrMsg());
LOG_ERROR( "KeywordMgr:" + db.GetLastErrMsg());
return flag;
}
Statement * p_stmt = db.GetStatement();
try
{
if (p_stmt)
{
p_stmt->setSQL( "begin PKG_KEYWORD_MANAGE.p_dir_add(:v1, :v2, :v3, :v4, :v5, :v6, :v7); end;" );
p_stmt->setString(1, CCommonUtil::ConvertBytesToString(dirInfo.Name));
p_stmt->setInt(2, parentDirId);
p_stmt->setInt(3, userId);
p_stmt->setString(4, CCommonUtil::ConvertBytesToString(dirInfo.Remark));
p_stmt->registerOutParam(5, OCCIINT);
p_stmt->registerOutParam(6, OCCIINT);
p_stmt->registerOutParam(7, OCCIINT);
p_stmt->execute();
dirId = p_stmt->getInt(5);
isHaveNode = p_stmt->getInt(6);
isParentExit = p_stmt->getInt(7);
}
}
catch (SQLException & ex)
{
LOG_ERROR(Poco::format( "Insert new dir info fail: %s" , ex.getMessage()));
CCommonUtil::ConvertStringToBytes(strErrMsg, Poco::format( "Insert new dir info fail: %s" , ex.getMessage()));
db.CloseConnection();
return -1;
}
db.CloseConnection();
if (!isParentExit)
return -3;
if (isHaveNode)
return -2;
LOG_INFO( "Add new dir successfully" );
return dirId;
} |
![](https://images0.cnblogs.com/blog/281401/201407/181907433969804.gif)
王安琪,英文名Angel,南京邮电大学计算机应用技术硕士学位。 熟悉Java、C#编程语言。专注于WebService、海量数据处理、搜索引擎技术、消息中间件技术、分布式文件存储、.NET应用程序开发、系统架构设计。主要从事大数据管理系统的研发,项目经理,系统架构师,就职于江苏金陵科技集团有限公司。
Email:aitanjupt@hotmail.com
QQ:289770363
当前题目:C++调用存储过程-创新互联
文章起源:http://myzitong.com/article/dhciss.html