前提
装好了 Hive
执行 bin/hiveserver2 开着别动,再开一个终端
lsof -i:10000 看是否打开了端口
bin/beeline -u jdbc:hive2://localhost:10000
就连上了
Maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-hadoop</artifactId>
<version>2.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.2.2</version>
</dependency>
Config
@Configuration
class Config {
@Bean
fun hiveDriver() = HiveDriver()
@Bean
fun hiveDataSource(driver: HiveDriver, @Value("\${hive.url}") hiveUrl: String) = SimpleDriverDataSource(driver, hiveUrl)
}
Main
@Component
class Main(val hive: JdbcTemplate) : CommandLineRunner {
override fun run(vararg args: String?) {
val b = hive.queryForList("select * from hello3")
b.forEach { it -> println(it) }
}
}
Properties
hive.url=jdbc:hive2://localhost:10000