java - jdbc to hive connection refused -


i trying connect hive via jdbc. below code using:

import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import java.sql.connection;  public class hivetojava {     private static string drivername = "org.apache.hadoop.hive.jdbc.hivedriver";      /**      * @param args      * @throws sqlexception      */     public static void main(string[] args) throws sqlexception {         try {             class.forname(drivername);         } catch (classnotfoundexception e) {              e.printstacktrace();             system.exit(1);         }         connection con = drivermanager.getconnection(                 "jdbc:hive://localhost:10000/default", "", "");         statement stmt = con.createstatement();         string tablename = "processed";         resultset res = stmt.executequery("describe " + tablename);         while (res.next()) {             system.out.println(res.getstring(1) + "\t" + res.getstring(2));         }      } } 

when run class java application, msg :

exception in thread "main" java.sql.sqlexception: not establish connection localhost:10000/default: java.net.connectexception: connection refused

please help.

try below code may output....

package com.services.connections;  import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement;  public class connecthive {   public static void main(string[] args) throws sqlexception,classnotfoundexception  {     // todo auto-generated method stub     string connectionurl = "jdbc:hive://localhost:9999/javatesting";     string drivername = "org.apache.hadoop.hive.jdbc.hivedriver";     string username = "";     string password = "";     try {         class.forname(drivername);             }          catch (classnotfoundexception e)           {         // todo auto-generated catch block         e.printstacktrace();         system.exit(1);           }           try {             connection con = drivermanager.getconnection(connectionurl, username, password);             if(con != null)              {             system.out.println("connected");                 }             else                 {             system.out.println("not connected");             }             statement stmt = con.createstatement();              // select * query             string sql;             resultset res;             sql = "select * javatesting.testdata";             system.out.println("running: " + sql);                 res = stmt.executequery(sql);             while (res.next())             {                   system.out.println(string.valueof(res.getstring(1)) + "\t" + res.getstring(2));             }               }           catch(sqlexception se)            {             se.printstacktrace();           }   }  } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -