【问题标题】:Postgresql :Calling of stored procedure through Java code with HibernatePostgresql:使用 Hibernate 通过 Java 代码调用存储过程
【发布时间】:2023-03-05 21:22:01
【问题描述】:

我在使用 lambda 表达式 (->{ ) 调用存储过程时遇到错误。

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

这是我使用 Prepared 调用存储过程的代码 声明。

    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();
    });
} 

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

提前致谢。

【问题讨论】:

    标签: java postgresql hibernate stored-procedures


    【解决方案1】:

    试试这个:

    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();
                    }
                }); 
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-12
      • 1970-01-01
      • 2023-03-20
      • 2019-07-10
      • 2013-03-07
      • 1970-01-01
      • 2021-04-18
      相关资源
      最近更新 更多