Multiple data sources in a single query using JDBCTemplate

I have two data sources DS1 and DS2. I am using the JDBC template. I have a conditional select statement, as shown below, which will use two data sources to select from DS1.table1 and DS2.table2.

Is it possible to connect two schemas in one JDBC request?

searchResult = this.jdbcTemplate.query(search_query, parameterValues.toArray(new Object[parameterValues.size()]), new ManageMapper());


StringBuilder search_query = new StringBuilder();
        search_query.append(...................);
        .
        .
        .
        .
        stringBuilder.append(" left  join schema1.table t1 on t1.emp_id = t111.emp_id ");

        if (searchRequest.getOnboardStatus() != null && (searchRequest.getOnboardStatus().equals("True")) {         
            stringBuilder.append(" inner join schema2.table2 t2 on t2.dept_id = t222.dept_id and t222.to_dt is null");
        }


@Autowired
@Qualifier(value = "jdbcDS1")
protected JdbcTemplate jdbcDS1Template;


@Autowired
@Qualifier(value = "jdbcDS2")
protected JdbcTemplate jdbcDS2Template;
+4
source share
1 answer

JDBC works at the DBMS level, generating SQL code to execute. SQL can be sent only 1 DBMS at a time. In special situations, the DBMS engine can execute a query in a distributed style, for example, in Oracle RAC or in a parallel query. However, the DBMS controls this.

, JDBC, , , JDBC . , , , , . Java 1 JDBC.

+1

Source: https://habr.com/ru/post/1621001/


All Articles