1

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.

1 Answer 1

1

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

    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.