JDBC调用存储过程

来源:互联网 发布:mac上好用的手绘软件 编辑:程序博客网 时间:2024/05/20 12:21
 public int addORDelAgentPerson(String strTableID,String strUserID,String strAgentID,String strType)throws Exception{        Connection conn= null;        CallableStatement cbst = null;        ResultSet rs = null;        String procedure = "{call SP_SetDevolvePerson(?,?,?,?)} ";        //int count = 0;        try{            conn = jbpu.getConnection();            conn.setAutoCommit(false);            cbst = conn.prepareCall(procedure);            cbst.setString(1, strTableID);            cbst.setString(2, strUserID);            cbst.setString(3, strAgentID);            cbst.setString(4, strType);            //count = cbst.executeUpdate();            cbst.executeUpdate();            conn.commit();            return 1;        }catch(Exception e){            conn.rollback();            e.printStackTrace();            return 0;        }finally{            jbpu.close(rs, cbst, conn);        }    }

注:

1、JDBC通过CallableStatement 接口调用存储过程;

2、jbpu是封装好的一个jdbc工具类实例;

3、jdbc传参的起始序号为1;

4、return 0或1,只是标识是否执行成功,也可用其它方式标识。

原创粉丝点击