简体   繁体   English

ResultSet为空,虽然sql查询正常,但是事件

[英]ResultSet is empty, event though the sql query is ok

I have the following Stored Procedure: 我有以下存储过程:

ALTER PROCEDURE Uspinformation3 (@TypeNr    VARCHAR(50), 
                                 @Process   VARCHAR(50), 
                                 @StartDate VARCHAR(50), 
                                 @EndDate   VARCHAR(50)) 
AS 
  BEGIN try 
      SET dateformat dmy; 

      SELECT Count(rownr) 
      FROM   diff_ct 
      WHERE  type_number = @TypeNr 
             AND process = @Process 
             AND full_time_stamp BETWEEN @StartDate AND @EndDate 
  END try 

If I execute the Procedure from SQL Server, it gives me the wanted answer 如果我从SQL Server执行过程,它会给我想要的答案

EXEC uspInformation3 1137328582, 427, 
                     {ts '2015-05-24 12:00:00'}, {ts  ' 2015-05-24 16:00:00 '}

But, when I try to do it from Java, the Result Set is always empty. 但是,当我尝试从Java执行此操作时,结果集始终为空。 Where am I doing a mistake? 我在哪里犯了错误? I guess that it has something to do with the data types that I am using? 我想这与我使用的数据类型有关?

 try {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
                Connection conn = DriverManager.getConnection(DB_Connection);

              String partno = pn.getText();
              String processname = procname.getText();
            // String StartTime =  DataStart.getText();  
      String StartTime = "{ts " +"'"+ DataStart.getText() +"'}";


            String EndTime = "{ts " +"'"+ DataFinal.getText()+"'}";


      System.out.println(StartTime);


            Statement state = conn.createStatement();
     CallableStatement cs = null;


     cs = conn.prepareCall("{call uspInformation3(?,?,?,?)}");
        cs.setString(1, partno);
        cs.setString(2, processname);
        cs.setString(3, StartTime);
        cs.setString(4, EndTime);
        cs.executeQuery();

       ResultSet rs = cs.getResultSet();

       System.out.println(rs);
        if(rs.next()) {

               String totalct = rs.getString(1);
               System.out.println(totalct);
           totalctno.setText(totalct);                      

          }

Did you try send the parameter as string? 您是否尝试将参数作为字符串发送? Or change the parameter type to datetime 或者将参数类型更改为datetime

Also there was extra spaces there on second date. 第二次约会时还有额外的空间。

EXEC uspInformation3 1137328582, 427, 
                     '2015-05-24 12:00:00', '2015-05-24 16:00:00';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM