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

时间:2016-05-28 10:55:47

标签: java sql-server resultset

我有以下存储过程:

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 

如果我从SQL Server执行过程,它会给我想要的答案

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

但是,当我尝试从Java执行此操作时,结果集始终为空。我在哪里犯了错误?我想这与我正在使用的数据类型有关?

 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);                      

          }

1 个答案:

答案 0 :(得分:0)

您是否尝试将参数作为字符串发送?或者将参数类型更改为datetime

第二次约会时还有额外的空格。

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