0

Ubuntu 16.04.1 LTS
hadoop 3.3.1
Hive 2.3.9

I have a java file:

public class HiveCreateDb {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    public static void main(String[] args) throws SQLException {
        // Register driver and create driver instance
        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.exit(1);
        }
        // get connection
        Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", "");
        Statement stmt = con.createStatement();
        stmt.executeQuery("CREATE DATABASE userdb");
        System.out.println("Database userdb created successfully.");
        con.close();
    }
}

I put this java file on ubuntu folder,and then run

javac HiveCreateDb.java 
HiveCreateDb.java:14: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown
        Class.forName(driverName);
                     ^
1 error

I have downloaded hive-jdbc-3.1.2.jar,where shall I put this jar?

Venus
  • 1,184
  • 2
  • 13
  • 32

1 Answers1

0

javac -classpath jars/hive-jdbc-2.3.9.jar source/HiveCreateDb.java

Venus
  • 1,184
  • 2
  • 13
  • 32