How to execute stored procedure/routine with JDBCIO (apache beam)

Chimmy :

i'm trying to execute a postgres routine using JDBCIO for apache beam.

So far I have tried:

 .apply(JdbcIO.<MyData>write()
                            .withDataSourceConfiguration(JdbcIO.DataSourceConfiguration.create(
                                    "org.postgresql.Driver", "jdbc:postgresql://localhost:5432/postgres")
                                    .withUsername("postgres")
                                    .withPassword("password"))

                            .withStatement("do $$\n" +
                                    "begin " +
                                    "perform test_routine(first := ?, second := ?, age := ?) " +
                                    "end\n" +
                                    "$$;")
                            .withPreparedStatementSetter(new JdbcIO.PreparedStatementSetter<MyData>() {
                                public void setParameters(MyData element, PreparedStatement query)
                                        throws SQLException {
                                    query.setString(1,element.mfirst);
                                    query.setString(2, element.second);
                                    query.setInt(3, element.age);
                                }
                            })
                    );

Unfortunately that gives me the error:

org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0

I have managed to get it working with a simple insert statement, but ideally would like to call a routine. Any help would be appreciated.

Chimmy :

Was very simple:

.withStatement("select test_routine(first := ?, second := ?, age := ?))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=158802&siteId=1