gpt4 book ai didi

java - 结果集为空,虽然 sql 查询没问题

转载 作者:太空宇宙 更新时间:2023-11-04 12:34:18 27 4
gpt4 key购买 nike

我有以下存储过程:

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

}

最佳答案

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

第二次约会时还有多余的空间。

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

关于java - 结果集为空,虽然 sql 查询没问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37498140/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com