我试图在 postgresql 中编写示例存储函数并使用 JDBC 提供的 CallableStatement 调用它们。
这是我的一些测试代码
Consumer bean =new Consumer();
CallableStatement pstmt = null;
try {
con.setAutoCommit(false);
String query = "{ ? = call getData( ? ) }";
pstmt = con.prepareCall(query);
pstmt.registerOutParameter(1, Types.OTHER);
pstmt.setInt(2,5);
pstmt.execute(); // execute update statement
bean=(Consumer)pstmt.getObject(1);
System.out.println("bean"+bean.getConsumer_name());
而我的存储函数的形式是 .
CREATE FUNCTION getData(int) RETURNS SETOF db_consumer AS $$
SELECT * FROM db_consumer WHERE consumer_id = $1;
$$ LANGUAGE SQL;
但是,当我尝试运行代码时出现以下错误。
org.postgresql.util.PSQLException: A CallableStatement was executed with an invalid number of parameters .
知道为什么会发生这种情况吗?