zoukankan      html  css  js  c++  java
  • java中调用存储过程

    数据库中的存储过程

    CREATE PROCEDURE [dbo].[Proc_deleteStuByNo]
     -- Add the parameters for the stored procedure here
     @stuNo char(7),
     @result int output
    AS
    BEGIN
     SET NOCOUNT ON;
     delete from studinfo where StudNo=@stuNo
     set @result=@@rowcount
    END

    java中调用存储过程:

    String stuno="a1";

    int result=0;

    Connection connection = ConnDB.getConection();
       CallableStatement callStm=null;
       try {
        callStm = connection.prepareCall("{call Proc_deleteStuByNo(?,?)}");
        callStm.setString("stuNo",stuno);//为CallableStatement对象添加输入参数
        callStm.registerOutParameter("result",java.sql.Types.INTEGER);//为CallableStatement对象注册输出参数  

     } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }
       try {
        callStm.executeUpdate();
        result = callStm.getInt("result");//获取输出参数中的值
       } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }finally{
        try {
         callStm.close();
         connection.close();
        } catch (SQLException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
        }   
       }
       if(result>0){
        System.out.println("删除成功");
       }else{

      System.out.println("删除失败");
        }

  • 相关阅读:
    Linux下安装Blender
    自我复制的3D打印机
    ODOO v10.0 自动生成财务凭证的科目设置
    初识Odoo的辅助核算
    Odoo9以后的社区版本和企业版功能上的区别
    06: linux中find查找命令总结
    02: shell中的if、case、for等语句
    01: shell基本使用
    05: 配置yum源
    04: linux基础总结-centos6.5
  • 原文地址:https://www.cnblogs.com/tianguook/p/2647894.html
Copyright © 2011-2022 走看看