如何使用 JDBCIO (apache beam) 执行存储的 procedure/routine
How to execute stored procedure/routine with JDBCIO (apache beam)
我正在尝试使用 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 := ?))
我正在尝试使用 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 := ?))