简体   繁体   中英

Postgresql :Calling of stored procedure through Java code with Hibernate

I am getting an error while using lambda expression(->{ ) for calling a stored procedure.

Error: org.postgresql.util.PSQLException: ERROR: syntax error at or near "{"

Here is the code I am using to call my stored procedure using 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();
    });
} 

I want to execute this stored procedure. Could you please help me with it by suggesting changes or modifying my current code.

Thanks in advance.

Try This :

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

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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