欢迎光临
我们一直在努力

利用游标返回结果集的的例子(Oracle 存储过程)-JSP教程,Java技巧及代码

建站超值云服务器,限时71元/月

在sqlplus中建立如下的内容:1、程序包

sql> create or replace package types  2  as  3      type cursortype is ref cursor;  4  end;  5  /

程序包已创建。

2、函数sql> create or replace function sp_listemp return types.cursortype  2  as  3      l_cursor    types.cursortype;  4  begin  5      open l_cursor for select id, title from cf_news order by id;–表的名字  6      return l_cursor;  7  end;  8  /

函数已创建。

3、过程

sql> create or replace procedure getemps( p_cursor in out types.cursortype )  2  as  3  begin  4        open p_cursor for select id, title from cf_news order by id;–表的名字  5  end;  6  /

过程已创建。

4、建立一个可执行的java控制台程序

import java.sql.*; import java.io.*; import oracle.jdbc.driver.*;  

class getvalues {   public static void main (string args [])                      throws sqlexception, classnotfoundexception   {       string driver_class = "oracle.jdbc.driver.oracledriver";       string connect_string = "jdbc:oracle:thin:@127.0.0.1:1521:database";

      string query = "begin :1 := sp_listemp; end;"; //此处调用前面建立的函数!      connection conn;

      class.forname(driver_class);       conn = drivermanager.getconnection(connect_string, "scott", "tiger");

      callablestatement cstmt = conn.preparecall(query);       cstmt.registeroutparameter(1,oracletypes.cursor);       cstmt.execute();       resultset rset = (resultset)cstmt.getobject(1);

      while (rset.next ())         system.out.println( rset.getstring (1) );         cstmt.close();   } }

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 利用游标返回结果集的的例子(Oracle 存储过程)-JSP教程,Java技巧及代码
分享到: 更多 (0)

相关推荐

  • 暂无文章