gpt4 book ai didi

java - MS SQL JDBC - SQLServerCallableStatement -execute() 返回 false

转载 作者:行者123 更新时间:2023-12-02 08:09:21 28 4
gpt4 key购买 nike

我已经编写了应该从我的 servlet 调用 MSSQL 2005 过程的代码。问题是该过程是从表中选择数据,所以我想获取 ResultSet 但结果集永远不会返回:( 我用另一个过程测试了该过程并且它有效,此外,客户端连接权限是 dbowner 所以不应该有连接出现问题,但执行仍然返回 false :(

这是问题代码(我检查了当前连接已连接):

...
SQLServerCallableStatement callableStatement = null;
callableStatement = (SQLServerCallableStatement) connection.prepareCall(
"{call "+
DATABASE_NAME+
"."+
SCHEMA_NAME+
".select_item_proc(?,?,?)}");

callableStatement.setInt(1, 0);
callableStatement.setString(2, "value1");
callableStatement.setString(3, "value2");

boolean rs=callableStatement.execute();

if(rs)
{
ResultSet result=callableStatement.getResultSet();




while (result.next()) {

String col1= result.getString(1);
String col2=result.getString(2);
System.out.print(col1+",");
System.out.println(col2);


}


}
...

所以我需要你重新审视问题到底是什么?任何有用的评论都会受到赞赏

最佳答案

请尝试使用 ResultSet rs = callableStatement.executeQuery(); 而不是 boolean rs=callableStatement.execute(); 行。

关于java - MS SQL JDBC - SQLServerCallableStatement -execute() 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7689781/

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