原文:

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))
    }


  }
}

 

相关文章:

  • 2021-09-29
  • 2021-11-20
  • 2022-01-14
  • 2021-05-16
  • 2021-12-08
  • 2022-12-23
猜你喜欢
  • 2021-12-04
  • 2021-06-12
  • 2021-12-12
  • 2021-05-18
  • 2021-05-13
  • 2021-04-16
  • 2021-07-10
相关资源
相似解决方案