drill java && spring jdbc 连接使用
2017-05-31 19:38
387 查看
原生 jdbc 连接
1. maven 包
2. 代码
3. 查询结果
使用spring boot jdbc
1. spring boot maven
2. 代码
3. 查询结果
null
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. 查询结果
null
相关文章推荐
- [Sqlite]-->Java使用jdbc连接Sqlite数据库进行各种数据操作的详细过程
- 使用jdbc连接mysql 出现 java.sql.Exception: this specifer does...(root@'%')..doesn't exist.
- [Java 8 & Spring JDBC] 使用Spring JDBC和Lambda表达式简化DAO
- Java 使用jdbc:odbc 建立无源连接access数据库
- JAVA学习:JDBC连接DB2数据库(2):使用配置文件
- java使用jdbc连接各种数据库
- Java/JSP中使用JDBC连接SQL Server 2005
- java使用jdbc轻松连接访问access
- Java/JSP中使用JDBC连接SQL Server 2005
- java application应用程序 使用JDBC和proxool两种方式连接数据库 的测试程序代码
- java中使用jdbc连接sql server 2005
- java使用jdbc轻松连接访问access
- JAVA学习笔记4——JDBC方式连接数据库
- java的JDBC连接mysql数据库时对于Datetime类型出现Cannot convert value '0000-00-00 00:00:00' from column 9 to TIMESTAMP
- 使用JDBC连接ODBC数据库的Java代码
- [转]Java/JSP中使用JDBC连接SQL Server 2005
- java的JDBC连接mysql数据库时对于Datetime类型出现Cannot convert value '0000-00-00 00:00:00' from column 9 to TIMESTAMP.
- 在java中使用jdbc的数据库连接大全
- Java/JSP中使用JDBC连接SQL Server 2005
- java中使用jdbc连接sql server 2005