java读取oracle_java读取oracle的存储过程

CREATE OR REPLACE package chapter_13 asTYPE rs IS REF CURSOR ;procedure founder(oFields out rs);end;CREATE OR REPLACE package body chapter_13 asPROCEDURE founder(oFields out rs) ISBEGIN open oFields for  select * from person;END founder;end;java代码package jdbc;import java.io.*;import java.sql.*;import java.text.*;import oracle.jdbc.OracleTypes;public class TestStoredProcedures {  Connection conn;  public TestStoredProcedures() {    try {      DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());      conn = DriverManager.getConnection(          "jdbc:oracle:thin:@localhost:1521:orcl", "jola", "jola");    } catch (SQLException e) {      System.err.println(e.getMessage());      e.printStackTrace();    }  }  public static void main(String[] args) throws Exception {    new TestStoredProcedures().process();  }  public void process() throws SQLException {       long start = 0;    long end = 0;    CallableStatement cstmt = null;    try {      start = System.currentTimeMillis();      // *** SQL92 escape syntax ***           cstmt = conn.prepareCall(          "{call chapter_13.founder(?)}");      cstmt.registerOutParameter(1, OracleTypes.CURSOR);      ResultSet rs = null;      cstmt.execute();       rs = (ResultSet)cstmt.getObject(1);      while (rs.next()) {        System.out.println(rs.getString("NAME"));      }      rs.close();      end = System.currentTimeMillis();      System.out.println("Average elapsed time = " +                (end - start) / 8 + " milliseconds");    } catch (SQLException e) {      System.err.println("SQL Error: " + e.getMessage());    } finally {      if (cstmt != null) {        try {          cstmt.close();        } catch (SQLException ignore) {}      }    }  }  protected void finalize() throws Throwable {    if (conn != null) {      try {        conn.close();      } catch (SQLException ignore) {}    }    super.finalize();  }}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值