0

Function definition:

CREATE OR REPLACE FUNCTION insert_json(
    p_name character varying,
    p_content jsonb)

Following java call ends with SQL Exception about need of param cast...

PreparedStatement ps = helper.prepareStatement(conn, "SELECT * FROM insert_json(?, ?)");
            ps.setString(1, name);

            PGobject pgo = new PGobject();
            pgo.setType("jsonb");
            pgo.setValue(content);

            ps.setObject(2, pgo);

PostgreSQL 9.4

1 Answer 1

1

Yes you must create PGobject and insert, but with some changes:

First:

PGobject pgo = new PGobject();
pgo.setType("jsonb");
pgo.setValue(content);

Second:

jdbcTemplate.update("SELECT yourFunction(?, ?)",
        new Object[] {text, pgo},
        new int[] {Types.VARCHAR, Types.OTHER });
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.