原生 jdbc 连接
1. maven 包
<dependency>
<groupId>org.apache.drill.exec</groupId>
<artifactId>drill-jdbc-all</artifactId>
<version>1.10.0</version>
</dependency>
2. 代码
Class.forName("org.apache.drill.jdbc.Driver");
Connection connection =DriverManager.getConnection("jdbc:drill:zk=10.10.5.18:2181/drill/demo");
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select * from dfs.`/root/drill/drill/sample-data/user.json`");
while(rs.next()){
System.out.println(rs.getString(1));
}
3. 查询结果
使用spring boot jdbc
1. spring boot maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.drill.exec</groupId>
<artifactId>drill-jdbc-all</artifactId>
<version>1.10.0</version>
</dependency>
2. 代码
a.DataSourceBean定义
@Bean(name="dataSource2")
publicDataSource dataSource2(){
BasicDataSource dataSource =newBasicDataSource();
dataSource.setUrl("jdbc:drill:zk=10.10.5.18:2181/drill/demo");
dataSource.setDriverClassName("org.apache.drill.jdbc.Driver");
dataSource.setInitialSize(2);
dataSource.setMaxActive(20);
dataSource.setMinIdle(0);
dataSource.setPoolPreparedStatements(true);
dataSource.setMaxWait(60000);
dataSource.setTestOnBorrow(false);
dataSource.setTestWhileIdle(true);
return dataSource;
}
b. jdbctempalte
@Bean
publicJdbcTemplate jdbcTemplate2(@Qualifier("dataSource2")DataSource dataSource2){
JdbcTemplate oracle =newJdbcTemplate();
oracle.setDataSource(dataSource2);
return oracle;
}
c.查询使用
@RestController
publicclassDrillController{
@Autowired
privateJdbcTemplate jdbcTemplate2;
@RequestMapping(value="/drill",method=RequestMethod.GET)
publicObject getUser3(){
return jdbcTemplate2.queryForList("select * from dfs.`/root/drill/drill/sample-data/user.json`");
}
}
3. 查询结果