使用Java-Cloudera在Hive中创建表

时间:2017-08-16 05:51:15

标签: java hive hdfs cloudera hiveql

尝试使用JAVA在Hive中创建一个新表。请帮我解决这个问题。

package Calllog;

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


public class HiveCreateTable {

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

    public static void CreateTable() 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/userdb", "", "");

          // create statement
          Statement stmt = con.createStatement();

          stmt.executeQuery("CREATE TABLE IF NOT EXISTS "
                     +" employee ( eid int, name String, "
                     +" salary String, destignation String)"
                     +" COMMENT ‘Employee details’"
                     +" ROW FORMAT DELIMITED"
                     +" FIELDS TERMINATED BY ‘\t’"
                     +" LINES TERMINATED BY ‘\n’"
                     +" STORED AS TEXTFILE;");

          System.out.println("Table Created !!");

                  con.close();
    }}

这是错误信息。提前谢谢

java.lang.ClassNotFoundException: org.apache.hadoop.hive.jdbc.HiveDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at Calllog.HiveCreateTable.CreateTable(HiveCreateTable.java:16)
    at Calllog.calllogmain.main(calllogmain.java:50)

以下是我要完成的工作,我在FTP中有一个Json数据并将此JSON复制到Local并转换为CSV并创建一个新的Hive表并将数据加载到HIVE中。

0 个答案:

没有答案