• 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     }
  • 相关阅读:
    汉诺塔问题
    opencv 增强现实(二):特征点匹配
    opencv 增强现实(一):特征点检测
    opencv 边缘检测原理
    opencv 图片旋转
    opencv 图片位移
    opencv 图片剪切
    opencv 图片缩放
    opencv 仿射变换
    opencv图像融合(大头)
  • 原文地址:https://www.cnblogs.com/cat-fish6/p/9515325.html
Copyright © 2020-2023  润新知