2016-03-29 36 views
0
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 [email protected] 
and [email protected] and hr=t1.hr) from hrtableView t1 where tagindex [email protected] 
and [email protected] group by hr; 


insert into #finalresults (hr, val) 
Select distinct hr,(Select top 1 val from hrtableView1 where [email protected] 
and [email protected] and hr=t1.hr) from hrtableView1 t1 where tagindex [email protected] 
and [email protected] group by hr; 

SELECT hr,val FROM #finalresults 
drop table #finalresults 

END 

GO 

error: The statement did not return a result set. 

我已经使用callable语句,但得到相同的错误。 我已经使用了Google的很多技巧,但一次又一次地得到同样的错误。声明在调用存储过程中没有返回结果集

+0

的PreparedStatement ST = con.prepareStatement( “{调用dbo.HrMin(,)?}”); st.setString(1,dateString); (2,7); st.setInt(2,7); boolean rs = st.execute(); System.out.println(“rss”+ rs);然后它打印rss错误 –

+0

把过程中的SET NOCOUNT ON将解决错误 –

回答

0

穿戴SET NOCOUNT ON在过程将解决错误

+0

我认为你应该将你的答案合并成一个答案并删除其他答案。 –

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 [email protected] 
and [email protected] and hr=t1.hr) from hrtableView t1 where tagindex [email protected] 
and [email protected] group by hr; 


insert into #finalresults (hr, val) 
Select distinct hr,(Select top 1 val from hrtableView1 where [email protected] 
and [email protected] and hr=t1.hr) from hrtableView1 t1 where tagindex [email protected] 
and [email protected] group by hr; 




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

GO