SLF4J:使用Jdbc连接到Hive时无法加载类“org.slf4j.impl.StaticLoggerBinder”

时间:2015-12-04 11:30:52

标签: java hive

我正在尝试使用找到herejdbc程序连接到配置单元:

package com.hive;

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

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

public static void main( String[] args )throws Exception{
    try {

        Class.forName(driverName);
        Connection connection = null;
            System.out.println("Before getting connection");
            connection=  DriverManager.getConnection("jdbc:hive://10.25.3.208:10000/default", "hive", "");
            System.out.println("After getting connection " + connection);

            ResultSet resultSet = connection.createStatement().executeQuery("select * from default.tstest");

            while (resultSet.next()) {
                System.out.println(resultSet.getString(1) + " " + resultSet.getString(2));
            }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

}

}

我将hive2更改为hive,并将驱动程序名称从org.apache.hive.jdbc.HiveDriver更改为org.apache.hadoop.hive.jdbc.HiveDriver

现在我收到以下错误:

Before getting connection
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.  

我的类路径中有以下jars

hive-common-0.8.1  
hive-metastore-0.8.1  
hive-service-0.8.1  
httpclient-4.3.3  
httpcore-4.2.1  
httpmime-4.3  
libfb303-0.9.0  
libthrift-0.9.0  
hive-exec-0.8.1  
hive-jdbc-0.10.0  
slf4j.api-1.6.1

1 个答案:

答案 0 :(得分:0)

您还需要在类路径中实现SLF4J。根据您要使用的日志记录系统,有多个选项。除非将内置于JRE中,否则必须添加所选的日志记录系统本身。

如果您不需要高级日志记录功能,一种简单的方法是添加slf4j-simple

有关详细信息,请查看documentation