我的 postgresql 数据库中有一个返回整数值的存储过程。当我使用 CallableStatement 从 jdbc 客户端调用我的过程时,当我在 CallableStatement 对象上调用 execute() 方法时,它只返回一个 boolean 值。如何读取函数的有效返回值?
最佳答案
您需要通过以下方式获取结果集:
ResultSet rs = stmt.executeQuery("SELECT * FROM setoffunc()");
while (rs.next()) {
// read results
}
rs.close();
stmt.close();
或者:
// Procedure call.
CallableStatement proc = conn.prepareCall("{ ? = call refcursorfunc() }");
proc.registerOutParameter(1, Types.OTHER);
proc.execute();
ResultSet results = (ResultSet) proc.getObject(1);
while (results.next()) {
// read results
}
results.close();
proc.close();
有关详细信息,请参阅文档:http://jdbc.postgresql.org/documentation/80/callproc.html
关于java - JDBC:检查存储过程返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17840049/