1

I have followed this doc to try to set up a jdbc connection to hive. But eclipse shows this error. Not seem to figure out what it exactly means and the connection with appropriate password and username works in beeline so its not the problem of authentication.Below is the error i'm facing:

> 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)

here is the code:

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);

  }
}
Jan
  • 13,738
  • 3
  • 30
  • 55
Codex
  • 569
  • 2
  • 6
  • 22
  • the same one for both. "org.apache.hive.jdbc.HiveDriver" – Codex Nov 30 '15 at 10:46
  • i've referenced the same hive-jdbc-1.2.1.jar from the installed hive library, so its the same used by beeline too ,if im not wrong.. will it be different for beeline? how to check the jar that beeline uses.. – Codex Nov 30 '15 at 10:55

1 Answers1

2

Your call to

if(con.isValid(0)){

is legal - but not implemented by the Hive JDBC Driver.

See Hive Source:

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

Replace the check with a simple if(con != null) and you'll be fine.

Jan
  • 13,738
  • 3
  • 30
  • 55
  • 1
    Thanks a lot! it worked.. i guess i took this line "A value of 0 indicates a timeout is not applied to the database operation. " in the wrong way. Can u kindly tell me what it means? It was mentioned if the timeout is less than 0 then an sql-exception will be thrown – Codex Nov 30 '15 at 11:15
  • You've done nothing wrong. You just encountered a method in java.sql.Connection that's rarely used (haven't seen it around a lot) so Hive Developers obviously opted to not implement that at all. – Jan Nov 30 '15 at 11:34