hive-2.3.6显示jdbc的log

vi hive-2.3.6/conf/hive-site.xml

<property>
  <name>hive.async.log.enabled</name>
  <value>false</value>
</property>

LogThread.java

package hive;

import java.sql.SQLException;
import java.sql.Statement;
import org.apache.hive.jdbc.HiveStatement;

public class LogThread extends Thread {

Statement stmt;

public LogThread(Statement stmt){
this.stmt = stmt;
}

public void run() { //真生的输出运行进度的thread
        if (stmt == null) {
            return;
        }
        HiveStatement hiveStatement = (HiveStatement) stmt;
        try {
            while (!hiveStatement.isClosed() && ((HiveStatement) stmt).hasMoreLogs()) {
                try {
                    for (String log : ((HiveStatement) stmt).getQueryLog(true, 100)) {
                        System.out.println(log);
                    }
Thread.sleep(500L);
                } catch (SQLException e) { //防止while里面报错,导致一直退不出循环
                    e.printStackTrace();
                    return;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    return;
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}


HAUpdate.java

package hive;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Date;

public class HAUpdate {

    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    private static String connctUrl = "jdbc:hive2://gpm:2181,gps:2181,gp1:2181,gp2:2181,gp3:2181/default;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2_zk";
    private static String userName = "root";
    private static String password = "123456";
    
    public static void main(String[] args) throws Exception {
    System.out.println(new Date());
       
    Class.forName(driverName);
        Connection con = DriverManager.getConnection(connctUrl, userName, password);
        
        System.out.println(new Date());
        
        Statement stmt = con.createStatement();
        new LogThread(stmt).start();
       
        stmt.executeUpdate("insert into t_test select * from t_test");
        
        stmt.close();
        con.close();
    }