求助 这段存储过程在java怎么调用 万分感激

cjk0506 2015-10-21 10:36:52
USE [by_furniture_hypsxt_sxysg]
GO
/****** Object: StoredProcedure [dbo].[Get_Code] Script Date: 10/21/2015 10:11:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/* 流水号 */
ALTER procedure [dbo].[Get_Code]
(@instr VarChar(13),@outstr varchar(13) Output)
As
Declare
@v_ParaName char(12),
@v_lb char(2),
@v_deptcode char(2),
@v_rq char(6),
@v_number Int,
@v_rqa char(6),
@v_numberstr Varchar(4),
@strMM VarChar(2),
@strDD VarChar(3),
@IntCount Int

Select @v_ParaName = Rtrim(ParaName)
From Dict_Parameter
where Paratypecode='08' and ParaCode=RTRIM(@Instr)
Select @IntCount=@@RowCount
Select @v_lb =SubString(@v_ParaName,1,2)
Select @v_rq = SubString(@v_ParaName,3,6)
Select @v_number =Convert(Int,substring(@v_ParaName,9,4))

Select @strMM = DATEPART(MM, GetDate())
if Convert(Int,@strMM) < 10
Select @strMM = '0' + @strMM
Select @strDD = DATEPART(DD, GetDate())
If Convert(Int,@strDD) < 10
Select @strDD = '0' + @strDD

Select @v_rqa =SubString(Convert(Char(4),DATEPART(YY, GetDate())),3,2) + @strMM + @strDD
if @v_rq=@v_rqa
begin
select @v_number = @v_number+1
select @v_numberstr = Convert(VarChar(4),@v_number)
While len(rTrim(@v_numberstr)) < 4
select @v_numberstr = '0' + @v_numberstr
Select @v_ParaName = @v_lb + @v_rq + @v_numberstr
Select @outstr = ltrim(rTrim(@v_ParaName))
end
else
Select @v_ParaName = @v_lb + @v_rqa + '0001'
if @IntCount=0
Select @v_ParaName = SubString(@InStr,1,2) + @v_rqa + '0001'
Select @outstr = ltrim(rTrim(@v_ParaName))
If @IntCount=0
Insert Into Dict_Parameter (ParaCode,ParaName,ParaTypeCode,ParaTypeName )
Values (@InStr,@v_ParaName,'08','单据')
Else
update Dict_Parameter set ParaName=@v_ParaName Where Paratypecode='08' and ParaCode=rtrim(@instr)
...全文
152 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wula0010 2015-10-23
  • 打赏
  • 举报
回复

public boolean procedureExecute(final String procedureName, final List params) throws AppException {
    boolean bResult= false;
    try {
        //获取数据库连接池
        conn = getConnection();
        try {
            cs = conn.prepareCall("{call " + procedureName + "}");
            logger.debug("准备存储过程成功:" + procedureName);
        } catch (SQLException se) {
            throw new AppException(this.getClass().getName() + ":_procedureExecute(final String procedureName, final List params):conn.prepareCall('{call " + procedureName + "()}):准备存储过程失败,SQLException 错误信息:" + se.getMessage());
        }
        //参数设置
        Iterator inputParamsIte = params.iterator();
        int index = 1;
        try {
            while (inputParamsIte.hasNext()) {
                cs.setObject(index, inputParamsIte.next());
                index++;
            }
        } catch (SQLException se) {
            throw new AppException(this.getClass().getName() + ":_procedureExecute(final String procedureName, final List params):cs.setObject(index, inputParamsIte.next())失败。object:" + inputParamsIte.toString() + "。SQLException错误信息:" + se.getMessage());
        }
        //执行存储过程
        try {
            cs.execute();
            bResult=true;
            logger.debug("执行存储过程成功:" + procedureName);
        } catch (SQLException se) {
            throw new AppException(this.getClass().getName() + ":_procedureExecute(final String procedureName, final List params):cs.execute():执行存储过程失败,SQLException 错误信息:" + se.getMessage());
        }
    } finally {
        closeConnection();
    }
    return bResult;
}
这个是没有返回值的存储过程调用,有返回的还不会,请其他高手补充下吧。
cscxxx 2015-10-23
  • 打赏
  • 举报
回复
以下是Stored Procedure各设置了一个in和out,getConnection()和一般连接DB一样自己网上搜下:

public String callSP(){
		String pkey = "";
	       CallableStatement cs;  
	       try {  
	       // 設定 CallableStatement  
	       cs = getConnection().prepareCall("{call sp_name(?,?)}");  
	         
	       //传给 in 
	       cs.setString(1, "1");
	       cs.registerOutParameter(2, java.sql.Types.VARCHAR);
	       // 运行 CallableStatement  
	       cs.execute();
               //获取OUT
	       pkey = cs.getString(2);
	       } catch (SQLException e) {  
	           e.printStackTrace();
	           pkey=e.getMessage();
	       }  

		return pkey;
	}

50,639

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧