scala 连接 hive

原文:

https://blog.csdn.net/weixin_42181917/article/details/82842707

简易版代码:

需要POM里面添加 jdbc-hive , 另外 需要启动 hive的 service2,

package hive
import java.sql.DriverManager
import java.sql.Connection
import java.sql.ResultSet
import java.sql.Statement

object Hive {
  def main(args: Array[String]): Unit = {

    val driverName:String = "org.apache.hive.jdbc.HiveDriver"
    try {
      Class.forName(driverName)
    } catch{
      case e: ClassNotFoundException =>
        println("Missing Class",e)
    }

    val con: Connection = DriverManager.getConnection("jdbc:hive2://192.168.1.11/hadoop")
    val stmt: Statement = con.createStatement()
    val res: ResultSet = stmt.executeQuery("show tables")
    while (res.next()) {
      println(res.getString(1))
    }


  }
}

猜你喜欢

转载自www.cnblogs.com/alpha-cat/p/12757942.html