Welcome 微信登录

首页 / 操作系统 / Linux / 在Java语言中访问游标类型详解

public class Testclass {
 private  static Connection conn;
 static{
  //加载驱动
  try {
   Class.forName("Oracle.jdbc.driver.OracleDriver");
  
   conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","scott");
  
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 
 }public static void testProcedure() throws SQLException{
   CallableStatement cas=conn.prepareCall("{call emppackage.selectEmps(?)}");
   int index=1;
   cas.registerOutParameter(index++,oracle.jdbc.OracleTypes.CURSOR);
   boolean flag=cas.execute();
   System.out.println(flag);
   //OracleCallableStatement 可使强制造型为oracle中的存储过程的对象
   //调用里面的getCursor方法获取返回的ResultSet的结果集
   ResultSet rs=((OracleCallableStatement)cas).getCursor(1);
   //遍历输出
   while(rs.next()){
    System.out.println(rs.getInt(1));
   
   
   }public static void functionTest2() throws SQLException{
    CallableStatement cas =conn.prepareCall("{?=call mypackage.queryEmps}");
   int index=1;
   cas.registerOutParameter(index++, oracle.jdbc.OracleTypes.CURSOR);
   boolean flag=cas.execute();
   System.out.println(flag);
   ResultSet rs=((OracleCallableStatement)cas).getCursor(1);
   while(rs.next()){
    System.out.println(rs.getInt(1));
   
   }}Linux防火墙配置shell脚本在Linux上用dd命令实现Ghost功能相关资讯      Java教程 
  • Java检测端口的占用情况  (09/25/2013 09:59:24)
  • Java中Comparator接口的用法  (02/07/2013 08:42:50)
  • Java有理数的四则运算  (02/01/2013 13:10:30)
  • Java中List.remove报错Unsupported  (04/27/2013 09:38:16)
  • Java两个线程轮换打印1-100内的奇  (02/01/2013 13:14:53)
  • Java垃圾回收机制与引用类型  (01/28/2013 10:54:24)
本文评论 查看全部评论 (0)
表情: 姓名: 字数