title: Read from database and write to file using camel
body: <p>I want to read from the database and write the records to a file using Camel. Below is my code:</p>
  
  <pre><code>import javax.sql.DataSource;
  import org.apache.camel.CamelContext;
  import org.apache.camel.builder.RouteBuilder;
  import org.apache.camel.impl.DefaultCamelContext;
  import org.apache.camel.impl.SimpleRegistry;
  import org.apache.commons.dbcp.BasicDataSource;
  
  public class JDBCExampleSimpleRegistry {
  
      public static void main(String[] args) throws Exception {
          final String url = "jdbc:oracle:thin:@MYSERVER:1521:myDB";
          DataSource dataSource = setupDataSource(url);
  
          SimpleRegistry reg = new SimpleRegistry() ;
          reg.put("myDataSource",dataSource);
  
          CamelContext context = new DefaultCamelContext(reg);
          context.addRoutes(new JDBCExampleSimpleRegistry().new MyRouteBuilder());
  
          context.start();
          Thread.sleep(5000);
          context.stop();
      }
  
      class MyRouteBuilder extends RouteBuilder {
          public void configure() {
              String dst = "C:/Local Disk E/TestData/Destination/?fileName=output.txt";
              from("direct:myTable")
                 .setBody(constant("select * from myTable"))
                 .to("jdbc:myDataSource")
                  .to("file://" + dst);
          }
      }
  
      private static DataSource setupDataSource(String connectURI) {
          BasicDataSource ds = new BasicDataSource();
          ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
          ds.setUsername("sa");
          ds.setPassword("devon1");
          ds.setUrl(connectURI);
          return ds;
      }
  }
  </code></pre>
  
  <p>The above program works fine and CamelContext is elegantly shutdown. However, the target file is not created. What am I doing wrong?</p>
  
  <p>I am a newbie to Apache Camel so appreciate any help. I am using JDK7 with Apache Camel 2.12.1 and is not using Spring.</p>