How can I read items from multiples databases? I already know that is possible from files.
the following example works for read from multiples files
...
I suggest a tricky way. If we assume that one is your mysql datasource's table is base and every row in that table corresponds other mysql datasource table's row(like a join tables which are in different datasources), you could do it in your batch job itemreader. Ex of this way;
Spring DataSource Configuration;
Your batch-job.xml
SELECT * FROM xyz
SELECT * FROM abc
Your RowMapper looks like;
public class MultiDatasourceRowMapper implements RowMapper {
private DataSource secondDataSource;
private String secondSql;
public String mapRow(ResultSet rs, int arg1) throws SQLException {
Connection conn = secondDataSource.getConnection();
PreparedStatement prep = conn.prepareStatement(secondSql);
// Do Something
return "";
}
public void setSecondDataSource(DataSource secondDataSource) {
this.secondDataSource = secondDataSource;
}
public void setSecondSql(String secondSql) {
this.secondSql = secondSql;
}
}