免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1320 | 回复: 1
打印 上一主题 下一主题

请教如何用java把调用存储过程的返回结果取出? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-09-04 11:31 |只看该作者 |倒序浏览
存储过程sql语句为"Declare myVal Integer; Begin......;End;"
myVal为返回结果,如何用java把它取得

论坛徽章:
0
2 [报告]
发表于 2004-09-04 17:32 |只看该作者

请教如何用java把调用存储过程的返回结果取出?

  1. This example demonstrates how to call stored procedures with IN, OUT, and IN/OUT parameters.
  2.     CallableStatement cs;
  3.     try {
  4.       // Call a procedure with no parameters
  5.         cs = connection.prepareCall("{call myproc}");
  6.         cs.execute();
  7.    
  8.       // Call a procedure with one IN parameter
  9.         cs = connection.prepareCall("{call myprocin(?)}");
  10.    
  11.         // Set the value for the IN parameter
  12.         cs.setString(1, "a string");
  13.    
  14.         // Execute the stored procedure
  15.         cs.execute();
  16.    
  17.       // Call a procedure with one OUT parameter
  18.         cs = connection.prepareCall("{call myprocout(?)}");
  19.    
  20.         // Register the type of the OUT parameter
  21.         cs.registerOutParameter(1, Types.VARCHAR);
  22.    
  23.         // Execute the stored procedure and retrieve the OUT value
  24.         cs.execute();
  25.         String outParam = cs.getString(1);     // OUT parameter
  26.    
  27.       // Call a procedure with one IN/OUT parameter
  28.         cs = connection.prepareCall("{call myprocinout(?)}");
  29.    
  30.         // Register the type of the IN/OUT parameter
  31.         cs.registerOutParameter(1, Types.VARCHAR);
  32.    
  33.         // Set the value for the IN/OUT parameter
  34.         cs.setString(1, "a string");
  35.    
  36.         // Execute the stored procedure and retrieve the IN/OUT value
  37.         cs.execute();
  38.         outParam = cs.getString(1);            // OUT parameter
  39.     } catch (SQLException e) {
  40.     }
复制代码




http://www.javaalmanac.com/egs/java.sql/CallProcedure.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP