• drill java && spring jdbc 连接使用


     原生 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  jdbc
    1. 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. 查询结果
      
     
  • 相关阅读:
    C#后台去除字符串最后一个字符
    C#后台验证含0的正整数
    jQuery提交表单的几种方式
    C#后台获取当前时间并格式化
    获取EasyUI日期输入框的值
    jQuery将字符串转换为数字
    JQ和JS获取span标签的内容
    正则
    json 拖拽
    event事件对象
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/6925663.html
Copyright © 2020-2023  润新知