gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 12:15:49 24 4
gpt4 key购买 nike

我正在尝试使用 JDBCIO 为 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 := ?))

关于java - 如何使用 JDBCIO (apache beam) 执行存储过程/例程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55277965/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com