⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 refcursorexample.java

📁 比较实用的C++编程思想 有很多例子可以用
💻 JAVA
字号:
/* * This sample shows how to call a PL/SQL function that opens * a cursor and get the cursor back as a Java ResultSet. */import java.sql.*;import java.io.*;// Importing the Oracle Jdbc driver package makes the code more readableimport oracle.jdbc.driver.*;class RefCursorExample{  public static void main (String args [])       throws SQLException  {    // Load the driver    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());    // Connect to the database    // You can put a database name after the @ sign in the connection URL.    Connection conn =      DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger");    // Create the stored procedure    init (conn);    // Prepare a PL/SQL call    CallableStatement call =      conn.prepareCall ("{ ? = call java_refcursor.job_listing (?)}");    // Find out all the SALES person    call.registerOutParameter (1, OracleTypes.CURSOR);    call.setString (2, "SALESMAN");    call.execute ();    ResultSet rset = (ResultSet)call.getObject (1);    // Dump the cursor    while (rset.next ())      System.out.println (rset.getString ("ENAME"));    // Close all the resources    rset.close();    call.close();    conn.close();  }  // Utility function to create the stored procedure  static void init (Connection conn)       throws SQLException  {    Statement stmt = conn.createStatement ();    stmt.execute ("create or replace package java_refcursor as " +		  "  type myrctype is ref cursor return EMP%ROWTYPE; " +		  "  function job_listing (j varchar2) return myrctype; " +		  "end java_refcursor;");    stmt.execute ("create or replace package body java_refcursor as " +		  "  function job_listing (j varchar2) return myrctype is " +		  "    rc myrctype; " +		  "  begin " +		  "    open rc for select * from emp where job = j; " +		  "    return rc; " +		  "  end; " +		  "end java_refcursor;");    stmt.close();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -