zoukankan      html  css  js  c++  java
  • java调用Oracle中的存储过程与存储函数

     1 //调用存储过程
     2     public static void testPro(){
     3         String driver = "oracle.jdbc.OracleDriver";
     4         String url = "jdbc:oracle:thin:@localhost:1521:orcl";
     5         Connection conn = null;
     6         CallableStatement cs = null;
     7         
     8         try {
     9             Class.forName(driver);
    10             conn = DriverManager.getConnection(url, "scott", "tiger");
    11             cs = conn.prepareCall("{call countyearsal(?,?)}");
    12             cs.setInt(1, 7369);
    13             //注册oracle输出参数的类型
    14             cs.registerOutParameter(2, OracleTypes.NUMBER);
    15             cs.execute();
    16             int ysal = cs.getInt(2);
    17             System.out.println(ysal);
    18         } catch (Exception e) {
    19             e.printStackTrace();
    20         }finally {
    21             try {
    22                 if(cs != null){
    23                     cs.close();
    24                 }
    25                 if(conn != null){
    26                     conn.close();
    27                 }
    28             } catch (SQLException e) {
    29                 e.printStackTrace();
    30             }
    31         }
    32     }
    33     //调用存储函数
    34     public static void testFun(){
    35         String driver = "oracle.jdbc.OracleDriver";
    36         String url = "jdbc:oracle:thin:@localhost:1521:orcl";
    37         Connection conn = null;
    38         CallableStatement cs = null;
    39         
    40         try {
    41             Class.forName(driver);
    42             conn = DriverManager.getConnection(url, "scott", "tiger");
    43             cs = conn.prepareCall("{?=call countysal(?)}");
    44             cs.setInt(2, 7369);
    45             //注册oracle输出参数的类型
    46             cs.registerOutParameter(1, OracleTypes.NUMBER);
    47             cs.execute();
    48             int ysal = cs.getInt(1);
    49             System.out.println(ysal);
    50         } catch (Exception e) {
    51             e.printStackTrace();
    52         }finally {
    53             try {
    54                 if(cs != null){
    55                     cs.close();
    56                 }
    57                 if(conn != null){
    58                     conn.close();
    59                 }
    60             } catch (SQLException e) {
    61                 e.printStackTrace();
    62             }
    63         }
    64     }
  • 相关阅读:
    超经典~超全的jQuery插件大全
    如何用PHP做到页面注册审核
    php实现签到功能
    php中的实用分页类
    微信小程序,超能装的实例教程
    php之 常用的 流程管理
    php之 人员的权限管理(RBAC)
    php之简单的文件管理(基本功能)
    php最新学习-----文件的操作
    关于LAMP的配置之(虚拟机的安装、创建、配置)
  • 原文地址:https://www.cnblogs.com/cat-fish6/p/9515325.html
Copyright © 2011-2022 走看看