172.7. 샘플

다음 예에서는 customer 테이블에서 행을 가져옵니다.

먼저 Camel 레지스트리에 testdb 로 데이터 소스를 등록합니다.

그런 다음 JDBC 구성 요소로 라우팅되는 경로를 구성하여 SQL을 실행합니다. 이전 단계에서 바인딩된 testdb 데이터 소스를 참조하는 방법을 참조하십시오.

또는 다음과 같이 Spring에서 DataSource 를 만들 수 있습니다.

끝점을 만들고, SQL 쿼리를 IN 메시지의 본문에 추가한 다음 교환을 보냅니다. 쿼리의 결과는 OUT 본문에서 반환됩니다.

전체 ResultSet 대신 하나의 행에 대해 작업하려면 다음과 같은 Splitter EIP를 사용해야 합니다.If you want to work on the rows one instead of the entire ResultSet at once you need to use the Splitter EIP such as:

from("direct:hello")
// here we split the data from the testdb into new messages one by one
// so the mock endpoint will receive a message per row in the table
// the StreamList option allows to stream the result of the query without creating a List of rows
// and notice we also enable streaming mode on the splitter
.to("jdbc:testdb?outputType=StreamList")
  .split(body()).streaming()
  .to("mock:result");