java.lang.ClassNotFoundException: org.apache.hadoo

2019-09-15 08:04发布

I am also add all jars file of usr/local/share/hadoop/mapreduce/*jars, usr/local/hadoop/common, hive-exec-xxx.jar, hive-metastore-xxx.jar and hive-jdbc-xxx.jar.

hive terminal working well.

My code is:

private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";

try {
        Class.forName(driverName);
        Connection con;

        con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", "");

        Statement stmt = con.createStatement();

        stmt.executeQuery("CREATE DATABASE demodb");
        System.out.println("Database userdb created successfully.");

        con.close();

    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

exception:

java.lang.ClassNotFoundException: org.apache.hadoop.hive.jdbc.HiveDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at hive.CRUDHive.main(CRUDHive.java:15)

标签: java hadoop hive
2条回答
Deceive 欺骗
2楼-- · 2019-09-15 08:30

In your code the driver class for hive is mentioned incorrectly. It shoul d be as below

private static String driverName = "org.apache.hive.jdbc.HiveDriver";

If the above change doesn't solve your problem then it means the jar files are not on the classpath which you need to add explicitely.

For the maven based project you can just add the dependency for hive-jdbc jar.

If you are not using maven then in eclipse do the following steps:

Select Project -> Build Path -> Configure Build Path -> Libraries -> Add external Jars -> Select path of hive-jdbc/hive-exec/hive-service jars

Along with hive jars you will need to add other dependent jars as a http-core, http-client, hadoop-common, commons-logging, slf4j jars.

查看更多
Viruses.
3楼-- · 2019-09-15 08:33

Make Sure which jar (hive ) do you want .. because it has diferent versions The old verison jar is

org.apache.hadoop.hive.jdbc.HiveDriver

here is the mvnrepository

and the newest jar is org.apache.hive.jdbc.HiveDriver here is the new settings

check your dependency please

查看更多
登录 后发表回答