Dear All:

We just installed and configured hive 1.2.1 and Hadoop on Ubuntu,
Everything worked  fine and we can query table from hive>
But when we tested jdbc from eclipse on windows client, there’re errors as 
follows, any advice would be appreciated,

Thanks
Joe

java.lang.ClassNotFoundException: org.apache.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:423)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Class.java:188)
     at MyHadoopProject.Hadoop_2_7_1.HiveJdbcClient.main(HiveJdbcClient.java:17)


Java source code:
package MyHadoopProject.Hadoop_2_7_1;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveJdbcClient {

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

    public static void main(String[] args)
                            throws SQLException {
        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        }

        // 參數是thrift的host:port、mysql帳號與密碼
        Connection con = DriverManager.getConnection(
                           "jdbc:hive2://192.168.112.172:10000/default", 
"test", "test");
        Statement stmt = con.createStatement();
        String tableName = "TestJDBCTable";
        // 刪掉已存在的table
        stmt.execute("drop table if exists " + tableName);
        // 建立TestJDBCTable table
        stmt.execute("create table " + tableName +
                                     " (key int, value string) row format 
delimited fields terminated by '\t'");
        System.out.println("Create table success!");
        // show tables
        String sql = "show tables '" + tableName + "'";
        System.out.println("Running: " + sql);
        ResultSet res = stmt.executeQuery(sql);
        if (res.next()) {
            System.out.println(res.getString(1));
        }
        // describe table
        sql = "describe " + tableName;
        System.out.println("Running: " + sql);
        res = stmt.executeQuery(sql);
        while (res.next()) {
            System.out.println(res.getString(1) + "\t" + res.getString(2));
        }

        // 將StudentFile資料匯入TestJDBCTable
        String filepath = "/home/csi/StudentFile.txt";
        sql = "load data local inpath '" + filepath + "' into table " + 
tableName;
        System.out.println("Running: " + sql);
        stmt.execute(sql);


        sql = "select * from " + tableName;
        res = stmt.executeQuery(sql);
        while (res.next()) {
            System.out.println(String.valueOf(res.getInt(1)) + "\t"
                                               + res.getString(2));
        }
    }
}


[PSC_logo_cutted]
TEL: 02 2658-1910 ext 2402  FAX: 02 2658-1920
Mobile: 0986-711896              Email: 
[email protected]<mailto:[email protected]>
ADD: 2nd Floor, No.18, Wenhu Street, Neihu District, Taipei City 114
[CSI-Logo]

Reply via email to