drill java && spring jdbc 串連使用

來源:互聯網
上載者:User

標籤:print   roo   use   dstat   request   next   version   gets   basic   

 原生 jdbc 串連 1. maven 包
  1. <dependency>
  2. <groupId>org.apache.drill.exec</groupId>
  3. <artifactId>drill-jdbc-all</artifactId>
  4. <version>1.10.0</version>
  5. </dependency>
2. 代碼
  1. Class.forName("org.apache.drill.jdbc.Driver");
  2. Connection connection =DriverManager.getConnection("jdbc:drill:zk=10.10.5.18:2181/drill/demo");
  3. Statement st = connection.createStatement();
  4. ResultSet rs = st.executeQuery("select * from dfs.`/root/drill/drill/sample-data/user.json`");
  5. while(rs.next()){
  6. System.out.println(rs.getString(1));
  7. }
3. 查詢結果  使用spring boot  jdbc1. spring boot maven 
  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-web</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.apache.drill.exec</groupId>
  7. <artifactId>drill-jdbc-all</artifactId>
  8. <version>1.10.0</version>
  9. </dependency>
2. 代碼
  1. a.DataSourceBean定義
  2. @Bean(name="dataSource2")
  3. publicDataSource dataSource2(){
  4. BasicDataSource dataSource =newBasicDataSource();
  5. dataSource.setUrl("jdbc:drill:zk=10.10.5.18:2181/drill/demo");
  6. dataSource.setDriverClassName("org.apache.drill.jdbc.Driver");
  7. dataSource.setInitialSize(2);
  8. dataSource.setMaxActive(20);
  9. dataSource.setMinIdle(0);
  10. dataSource.setPoolPreparedStatements(true);
  11. dataSource.setMaxWait(60000);
  12. dataSource.setTestOnBorrow(false);
  13. dataSource.setTestWhileIdle(true);
  14. return dataSource;
  15. }
  16. b. jdbctempalte
  17. @Bean
  18. publicJdbcTemplate jdbcTemplate2(@Qualifier("dataSource2")DataSource dataSource2){
  19. JdbcTemplate oracle =newJdbcTemplate();
  20. oracle.setDataSource(dataSource2);
  21. return oracle;
  22. }
  23. c.查詢使用
  24. @RestController
  25. publicclassDrillController{
  26. @Autowired
  27. privateJdbcTemplate jdbcTemplate2;
  28. @RequestMapping(value="/drill",method=RequestMethod.GET)
  29. publicObject getUser3(){
  30. return jdbcTemplate2.queryForList("select * from dfs.`/root/drill/drill/sample-data/user.json`");
  31. }
  32. }
3. 查詢結果  
  



null



drill java && spring jdbc 串連使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.