Java使用JDBC连接hive

一、上代码

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class HiveJdbcTest {
	
	private static String driverName = "org.apache.hive.jdbc.HiveDriver";

	public static void main(String[] args) throws SQLException {
		try {
			Class.forName(driverName);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.exit(1);
		}
		Connection con = DriverManager.getConnection("jdbc:hive2://ip:prot/databaseName;auth=noSasl", "", "");
		Statement stmt = con.createStatement();
		String sql = "SELECT * FROM tableName";
		ResultSet res = stmt.executeQuery(sql);
		while (res.next()) {
			System.out.println(res.getString(1));
		}
	}
}

二、依赖包

Java使用JDBC连接hive_第1张图片

你可能感兴趣的:(Java,JDBC,Hive)