如何在Java中执行Hive命令或HiveQL

2024-12-16 13:24:29
推荐回答(1个)
回答1:

String sql="show tables; select * from test_tb limit 10";
List command = new ArrayList();
command.add("hive");
command.add("-e");
command.add(sql);
List results = new ArrayList();
ProcessBuilder hiveProcessBuilder = new ProcessBuilder(command);
hiveProcess = hiveProcessBuilder.start();
BufferedReader br = new BufferedReader(new InputStreamReader(
hiveProcess.getInputStream()));
String data = null;
while ((data = br.readLine()) != null) {
results.add(data);
}