core-site.xml
<property>
<name>hadoop.proxyuser.zhang.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.zhang.groups</name>
<value>*</value>
</property>
public class HiveTest {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
Class.forName("org.apache.hive.jdbc.HiveDriver");
Connection connection = DriverManager.getConnection("jdbc:hive2://127.0.0.1:11000/default","zhang","");
Statement stat = connection.createStatement();
String sql = "show databases";
System.out.println("查询数据库,脚本:{}" + sql);
try (Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(sql)) {
while (rs.next()) {
System.out.println("查询到数据库:{}" + rs.getString(1));
}
} catch (SQLException e) {
System.out.println("创建数据库出错" + e);
}
connection.close();
}
}