Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
Hive >> mail # user >> can not connect hive through jdbc


+
ch huang 2013-07-10, 07:04
Copy link to this message
-
Re: can not connect hive through jdbc
Can you tell use which jdbc version are you using? and try changing it
to "jdbc:hive"
from " jdbc:hive2"
On Wed, Jul 10, 2013 at 12:34 PM, ch huang <[EMAIL PROTECTED]> wrote:

> i use following java code
>
>
> import java.sql.Connection;
>   import java.sql.DriverManager;
>   import java.sql.ResultSet;
>   import java.sql.Statement;
>
>   public class DemoHive {
>             public static void main(String[] args) throws  Exception {
>                 Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
>
>                 String dropSQL="drop table javabloger";
>                 String createSQL="create table javabloger (key int, value
> string)";
>                 String insterSQL="LOAD DATA LOCAL INPATH
> '/work/hive/examples/files/kv1.txt' OVERWRITE INTO TABLE javabloger";
>                 String querySQL="SELECT * FROM hb_dmp_pageview";
>
>                 Connection con = DriverManager.getConnection("jdbc:hive2://
> 192.168.10.22:10000/default", "", "");
>                 Statement stmt = con.createStatement();
>        //         stmt.executeQuery(dropSQL);  // 执行删除语句
>          //       stmt.executeQuery(createSQL);  // 执行建表语句
>         //        stmt.executeQuery(insterSQL);  // 执行插入语句
>                 ResultSet res = stmt.executeQuery(querySQL);   // 执行查询语句
>
>                   while (res.next()) {
>                     System.out.println("Result: key:"+res.getString(1) +"
> �>  value:" +res.getString(2));
>                 }
>             }
>         }
>
>
> Exception in thread "main" java.sql.SQLException: Invalid URL:
> jdbc:hive2://192.168.10.22:10000/default
>  at
> org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:85)
>  at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
>  at java.sql.DriverManager.getConnection(Unknown Source)
>  at java.sql.DriverManager.getConnection(Unknown Source)
>  at DemoHive.main(DemoHive.java:17)
>
>
> and in hive server
>
> # nohup hive --service hiveserver &
>
> # netstat -utlpn|grep 10000
> tcp        0      0 0.0.0.0:10000               0.0.0.0:*
> LISTEN      18430/java
>

--
Nitin Pawar
+
ch huang 2013-07-10, 07:17