繁体   English   中英

如何使用 JDBCIO (apache beam) 执行存储过程/例程

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

我正在尝试使用 JDBCIO for apache beam 执行 postgres 例程。

到目前为止,我已经尝试过:

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

不幸的是,这给了我错误:

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

我已经设法用一个简单的插入语句让它工作,但理想情况下想调用一个例程。 任何帮助,将不胜感激。

非常简单:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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