繁体   English   中英

Postgresql:使用Hibernate通过Java代码调用存储过程

[英]Postgresql :Calling of stored procedure through Java code with Hibernate

使用 lambda 表达式(->{) 调用存储过程时出现错误。

错误:org.postgresql.util.PSQLException:错误:“{”处或附近的语法错误

这是我用来使用 Prepared Statement 调用存储过程的代码。

    public void deleteData(Session session, int minVal, int maxVal) throws SQLException {
    session.doWork(connection -> {
        PreparedStatement st = connection.prepareStatement("{call delete_data(" + minVal + "," + maxVal + ")}");
        st.execute();
    });
} 

我想执行这个存储过程。 您能否通过建议更改或修改我当前的代码来帮助我。

提前致谢。

尝试这个 :

public void deleteData(Session session, int minVal, int maxVal) throws SQLException {
    session.doWork(new Work() {
                @Override
                public void execute(Connection connection) throws SQLException {
                    CallableStatement st = null;
                    st = connection.prepareCall("{call delete_data(?,?)}");
                    st.setInt(1, minVal);
                    st.setInt(2, maxVal);
                    st.execute();
                    st.close();
                }
            }); 

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM