我正在尝试使用以下驱动程序从Java程序连接到impala
com.cloudera.impala.jdbc41.Driver
但是这样做会遇到运行时异常,下面是堆栈跟踪
Exception in thread "main" java.lang.NoSuchFieldError: HIVE_CLI_SERVICE_PROTOCOL_V6
at com.cloudera.hivecommon.api.HS2Client.openSession(Unknown Source)
at com.cloudera.hivecommon.api.HS2Client.<init>(Unknown Source)
at com.cloudera.hivecommon.api.HiveServer2ClientFactory.createClient(Unknown Source)
at com.cloudera.hivecommon.core.HiveJDBCCommonConnection.connect(Unknown Source)
at com.cloudera.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
at com.cloudera.jdbc.common.AbstractDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:233)
我还附上以下代码供参考
Class.forName("com.cloudera.impala.jdbc41.Driver");
Connection connection = null;
connection =DriverManager.getConnection("jdbc:impala://IP:21050/default;user=foo;password=bar") ;
Statement statement = null;
statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select count(*) from table");
while (resultSet.next()) {
System.out.println(resultSet.getInt(0));
}