This project showcases how to connect to Hiveserver2 using a variety of different methods.
All the classes work only with Hiveserver2.
Cloudera JDBC drivers are being used which can be downloaded from here.
At the time of writing this, latest version is v2.5.15.
You need to download the drivers and copy them to the lib folder.
- Download the zip from from here for the correct OS and architecture.
 - Unzip and go to 
Cloudera_HiveJDBC41_xxxfolder. - Copy all the jars from there to the 
libfolder. 
JDBC API v3.x supports JRE v4.0 or v5.0
JDBC API v4.x supports JRE v6.0 or later
JDBC API v4.1.x supports JRE v7.0 or later
The Cloudera JDBC Driver for Apache Hive supports Hive 0.11, 0.12, 0.13, 0.14, 1.0, and 1.1.
Refer to the PDF documentation in the downloaded zip for more information.
- Do change the JDBC URL given at the starting of each class according to your cluster.
 - If the table 
sample_07does not exist indefaultdatabase, change the query accordingly. pom.xmlcontains Java version as 1.8. If you don't have 1.8, change the version accordingly.
There are 4 examples in this project:
- 
Hive2User
This class works with
hive.server2.authenticationset toNone. You need to specify the username only. - 
Hive2UserPswd
This class works with
hive.server2.authenticationset toLDAPorNone. You need to specify both the username and password. - 
Hive2KerberosKinit
This class works with
hive.server2.authenticationset toKerberos. The onus of generating a valid Kerberos ticket lies with the client. This assumes that:- Kerberos client utilities are installed in the system.
 - Valid krb5.ini file is present in 
/etc/krb5.ini - Client has obtained a valid ticket beforehand by calling 
kinitor authenticating with a validkeytabfile. 
 - 
Hive2KerberosTGT
This class also works with
hive.server2.authenticationset toKerberos. However, in this case, the code/driver obtains the Kerberos ticket. The code needs 3 files (currently present inconfdirectory):kerberos_login_config.inikrb5.ini<username>.keytab
Requisites:
- Obtain a valid 
krb5.inifile from your Kerberos administrator and place it in theconfdirectory. - Obtain a valid 
keytabfile for your principal from your Kerberos administrator and place it inconfdirectory with the name as<username>.keytab. - Modify 
kerberos_login_config.iniand change these 2 settings:keyTab: should point to the correct keytab file. Relative paths work. Replace<username>with the correct one.principal: insert the correct principal. This consists of 2 parts: username and realm. Replace<username>with the correct one as above. Replace<REALM>with the correct one. This should all be in caps. You can find the correct realm in thekrb5.inifile provided to you by the admin.
 - Make sure you can connect to the hosts pointed to in the 
krb5.inifile. If neccessary, add entries in thehostsfile.