Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Spring的JDBCTemplate执行PostgreSQL函数?_Sql_Spring_Postgresql_Jdbctemplate - Fatal编程技术网

如何使用Spring的JDBCTemplate执行PostgreSQL函数?

如何使用Spring的JDBCTemplate执行PostgreSQL函数?,sql,spring,postgresql,jdbctemplate,Sql,Spring,Postgresql,Jdbctemplate,我创建了一个自定义PostgreSQL函数: create function delete_classes() returns void as $$ DELETE FROM ...; $$ language sql; 我想用Spring的JDBCTemplate调用这个函数。我尝试了以下方法: @Repository class Repository { private final JdbcTemplate template; // initialized in constru

我创建了一个自定义PostgreSQL函数:

create function delete_classes() returns void as
$$
    DELETE FROM ...;
$$ language sql;
我想用Spring的JDBCTemplate调用这个函数。我尝试了以下方法:

@Repository
class Repository {
    private final JdbcTemplate template; // initialized in constructor

    public void deleteClasses() {
        template.update("select delete_classes()");
    }
}
我得到以下错误:

Caused by: org.springframework.dao.DataIntegrityViolationException:
PreparedStatementCallback; SQL [select delete_classes()];
A result was returned when none was expected.;
nested exception is org.postgresql.util.PSQLException:
A result was returned when none was expected.
PostgreSQL函数
delete_classes
返回
void
,因此我不确定这里的意思。
DELETE
语句没有
RETURNING…
子句

执行函数的正确方法是什么

更新

我尝试了以下操作(
execute
而不是
update
):

这里,它以lambda方式实现了一个
PreparedStatementCallback
,它只返回null


现在没有调用函数
delete\u classes

不要使用
update()
使用
execute()
我试过了,但我不确定如何实现
PreparedStatementCallback
回调,因为我不需要任何结果。见问题更新。
@Repository
class Repository {
    private final JdbcTemplate template; // initialized in constructor

    public void deleteClasses() {
        template.execute("select delete_classes()", statement -> null);
    }
}