无效操作的JDBC到hive连接失败isValid()

时间:2015-11-30 10:00:05

标签: java eclipse hadoop jdbc hive

我已按照this doc尝试设置与hive的jdbc连接。但是eclipse显示了这个错误。似乎没有弄清楚它究竟意味着什么,并且与适当的密码和用户名的连接在直线上工作,所以它不是身份验证的问题。下面是我面临的错误:

> 15/11/27 13:15:41 INFO jdbc.Utils: Supplied authorities: localhost:10000
> 15/11/27 13:15:41 INFO jdbc.Utils: Resolved authority: localhost:10000
> 15/11/27 13:15:41 INFO jdbc.HiveConnection: Will try to open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default
> Exception in thread "main" java.sql.SQLException: Method not supported
    at org.apache.hive.jdbc.HiveConnection.isValid(HiveConnection.java:1026)
    at HiveJDBC.main(HiveJDBC.java:21)

这是代码:

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

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

  public static void main(String[] args) throws SQLException {
    try {
      Class.forName(driverName);

    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      System.exit(1);
    }
    Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "hive", "PASSWORD");
    if(con.isValid(0)){
        System.out.println("success");
    }else{
        System.out.println("fail");
    }

    Statement stmt = con.createStatement();
    String tableName = "tabledriver";
    //stmt.executeQuery("create database " + tableName);

  }
}

1 个答案:

答案 0 :(得分:2)

致电

if(con.isValid(0)){

legal - 但Hive JDBC Driver没有实现

请参阅Hive Source

@Override
public boolean isValid(int timeout) throws SQLException {
  // TODO Auto-generated method stub
  throw new SQLException("Method not supported");
}

用简单的if(con != null)替换支票,你会没事的。