简体   繁体   English

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

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

i'm trying to execute a postgres routine using JDBCIO for apache beam.我正在尝试使用 JDBCIO for apache beam 执行 postgres 例程。

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.任何帮助,将不胜感激。

非常简单:

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

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

相关问题 JdbcIO.read 未在 apache 光束中返回结果 - JdbcIO.read is not returning results in apache beam 我们可以在具有Apache Beam管道的单个C​​loudSQL连接中的JDBCIO.write函数中执行多个插入查询吗? - Can we execute multiple insert queries in JDBCIO.write function in single CloudSQL connection with an apache beam pipeline? 如何在 Apache Delta Spike 中执行存储过程 - How to execute a stored procedure in Apache Delta Spike Null 在 Apache Beam [DataFlow] 中读取 JdbcIO 的指针异常 - Null Pointer Exception with JdbcIO read in Apache Beam [DataFlow] Apache Beam Wait.on JdbcIO.write 与无限 PCollection 问题 - Apache Beam Wait.on JdbcIO.write with unbounded PCollection issue JDBCIO调用以自定义对象类型为参数的Postgres例程(存储过程) - JDBCIO Calling Postgres Routine (Stored Proc) which takes a Custom Object Type as parameter 如何在hibernate 3中执行存储过程 - how to execute the stored procedure in hibernate 3 如何并行执行oracle java存储过程 - How to execute oracle java stored procedure in parallel 如何使用JAVA异步执行存储过程 - how to execute stored procedure asynchronously using JAVA 如何使用Spring Batch在Postgresql中执行存储过程? - How to execute a stored procedure in postgresql with spring batch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM