存储过程编程示例

procedure

/*创建环境句柄、到数据库的连接 和 statement*/
Environment *env = Environment::createEnvironment();
Connection *conn = env->createConnection(user,pwd,link);
Statement *stmt = conn->createStatement();

string pro1="CREATE OR REPLACE PROCEDURE pro11(a INT,n INT ,b OUT BLOB)\
                      AS \
                      BEGIN \
                      b:=NULL ;\
                      END; ";
string exec_sql = "begin pro11(:1,:2,:3); end;";
string drop_pro ="drop procedure pro11";
ResultSet *rs;
stmt->execute(drop_pro);
stmt->execute(pro1);

/*insert语句通过变量绑定参数*/
stmt->setSQL(exec_sql);
stmt->setInt(1,100);
stmt->setInt(2,200);
stmt->registerOutParam(3,OCCIBLOB);

stmt->execute();

// 测试out Blob
Blob b = stmt->getBlob(3);
b.close();

Blob b = stmt->getBlob(3);
b.open();

Blob b = stmt->getBlob(3);
bool in = b.isNull();

/*释放statement、数据库连接 和 环境句柄*/
conn->terminateStatement(stmt);
env->terminateConnection(conn);
Environment::terminateEnvironment(env);