172.7. サンプル

次の例では、customer テーブルから行をフェッチします。

まず、データソースを Camel レジストリーに testdb として登録します。

次に、JDBC コンポーネントにルーティングするルートを設定して、SQL が実行されるようにします。前のステップでバインドされた testdb データソースを参照する方法に注意してください。

または、次のように Spring で DataSource を作成できます。

エンドポイントを作成し、IN メッセージの本文に SQL クエリーを追加して、エクスチェンジを送信します。クエリーの結果は、OUT ボディーで返されます。

一度に ResultSet 全体ではなく、行を 1 つずつ処理する場合は、次のようなスプリッター EIP を使用する必要があります。

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");