You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Mich Talebzadeh <mi...@gmail.com> on 2016/03/22 10:55:44 UTC

Re: jdbc failed

Two things

In Eclipse have you added Hive jar files as external Jars to your libs in
Build path?

I will try to run the same JAVA code on the host that you have Hive
installed and you have defined your CLASSPATH first. If your JAVA program
works OK then you have an issue with your eclipse libraries.

HTH


Dr Mich Talebzadeh



LinkedIn * https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw
<https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw>*



http://talebzadehmich.wordpress.com



On 22 March 2016 at 09:46, 2402 楊建中 joeyang <jo...@pershing.com.tw> wrote:

> 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));
>
>         }
>
>     }
>
> }
>
>
>
>
>
> *[image: PSC_logo_cutted]*
>
> *TEL*: 02 2658-1910 ext 2402  *FAX*: 02 2658-1920
>
> *Mobile*: 0986-711896              *Email*: *joeyang@pershing.com.tw
> <jo...@pershing.com.tw>*
>
> *ADD*: 2nd Floor, No.18, Wenhu Street, Neihu District, Taipei City 114
>
> [image: CSI-Logo]
>
>
> ===================================================
> 本通訊及其所有附件所含之資訊均屬機密,僅供指定之收件人使用,未經寄件人許可不得揭露、複製或散布本通訊。
> 若您並非指定之收件人,請勿使用、保存或揭露本通訊之任何部份, 並請即通知寄件人並完全刪除本通訊。
> 本通訊僅供參考,且不應視為任何要約、要約之引誘、或締結契約或交易之確認或承諾。 寄件人並不保證本通訊內所載數據資料或其他資訊之完整性及正確性,
> 該等資料或資訊並得隨時不經通知而變更。 又本通訊之評論或陳述不當然反映北祥股份有限公司係之意見或看法。
> 網路通訊可能含有病毒,收件人應自行確認本郵件是否安全,若因此造成損害,寄件人恕不負責。
> ===================================================