在调用存储过程期间,该语句未返回结果集

时间:2016-03-29 10:49:54

标签: java

String dateString = null;
SimpleDateFormat sd = new SimpleDateFormat("yyyy/MM/dd");
dateString = sd.format(pumpTime);

PreparedStatement st = con.prepareStatement("{call dbo.HrMin(?,?)}");   st.setString(1,dateString);      
st.setInt(2,7);   
ResultSet rs = st.executeQuery();    while(rs.next())  {}  

procedure is :
USE [NC26]
GO

/****** Object:  StoredProcedure [dbo].[HrMin]    Script Date: 03/29/2016 15:40:56 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[HrMin]
    -- Add the parameters for the stored procedure here
    @date varchar(10),@tagindex smallint
AS
BEGIN

declare @datenew datetime;
-- To datetime datatype
set @datenew=DATEADD(DD,-1,(SELECT CONVERT(datetime, @date)));
set @datenew=CONVERT(varchar(10), @datenew, 111);
create table #finalresults
(
    hr int,
    val float

)

-- insert the survey table structures for use

insert into #finalresults (hr, val)
Select distinct hr,(Select top 1 val from hrtableView where tagindex=@tagindex 
and dt=@date and hr=t1.hr ) from hrtableView t1 where tagindex =@tagindex
and dt=@date  group by hr;


insert into #finalresults (hr, val)
Select distinct hr,(Select top 1 val from hrtableView1 where tagindex=@tagindex 
and dt=@date and hr=t1.hr ) from hrtableView1 t1 where tagindex =@tagindex
and dt=@date  group by hr;

SELECT hr,val FROM #finalresults
drop table #finalresults

END

GO

error: The statement did not return a result set.

我使用了可调用语句,但是出现了同样的错误。 我曾经使用过谷歌的这么多技巧,但一次又一次地犯了同样的错误。

2 个答案:

答案 0 :(得分:0)

在程序中按SET NOCOUNT将解决错误

答案 1 :(得分:0)

USE [NC26]
GO

/****** Object:  StoredProcedure [dbo].[test]    Script Date: 03/30/2016 10:26:42 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[test] 
    -- Add the parameters for the stored procedure here
    @date varchar(10),@tagindex smallint
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    declare @datenew datetime;

    create table #finalresults
(
    hr int,
    val float

)

insert into #finalresults (hr, val)
Select distinct hr,(Select top 1 val from hrtableView where tagindex=@tagindex 
and dt=@date and hr=t1.hr ) from hrtableView t1 where tagindex =@tagindex
and dt=@date  group by hr;


insert into #finalresults (hr, val)
Select distinct hr,(Select top 1 val from hrtableView1 where tagindex=@tagindex 
and dt=@date and hr=t1.hr ) from hrtableView1 t1 where tagindex =@tagindex
and dt=@date  group by hr;




SELECT hr,val FROM #finalresults
drop table #finalresults
END

GO