服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

java调用oracle的过程和函数

内容或简介:

/**

调用数据库里的一个函数

一个函数本质上一个返回一个结果的存储过程,这个例子示范了怎么调用有in、out和in/out参数的函数

***********************************/

callablestatement cs;

try {

// 调用一个没有参数的函数; 函数返回 a varchar

// 预处理callable语句

  cs = connection.preparecall("{? = call myfunc}");



// 注册返回值类型

cs.registeroutparameter(1, i);



// execute and retrieve the returned value

cs.execute();

string retvalue = cs.getstring(1);



// 调用有一个in参数的函数; the function returns a varchar

cs = connection.preparecall("{? = call myfuncin(?)}");



// register the type of the return value

cs.registeroutparameter(1, types.varchar);



// set the value for the in parameter

cs.setstring(2, "a string");



// execute and retrieve the returned value

cs.execute();

retvalue = cs.getstring(1);



// 调用有一个out参数的函数; the function returns a varchar

cs = connection.preparecall("{? = call myfuncout(?)}");



// register the types of the return value and out parameter

cs.registeroutparameter(1, types.varchar);

cs.registeroutparameter(2, types.varchar);



// execute and retrieve the returned values

cs.execute();

retvalue = cs.getstring(1);           // return value

string outparam = cs.getstring(2);    // out parameter



// 调用有一个in/out参数的函数; the function returns a varchar

cs = connection.preparecall("{? = call myfuncinout(?)}");



// register the types of the return value and out parameter

cs.registeroutparameter(1, types.varchar);

cs.registeroutparameter(2, types.varchar);



// set the value for the in/out parameter

cs.setstring(2, "a string");



// execute and retrieve the returned values

cs.execute();

retvalue = cs.getstring(1);           // return value

outparam = cs.getstring(2);           // in/out parameter

} catch (sqlexception e) {

}

扫描关注微信公众号