Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get database username and password in hive

Am writing jdbc program to connect hive database. I want the username and password to give it in the connection url.

I don't know how to get the username and password using hive QL. Can anybody help me out??

Exception in thread "main" java.sql.SQLNonTransientConnectionException: [DataDirect][Hive JDBC Driver]A value was not specified for a required property: PASSWORD
    at com.ddtek.jdbc.hivebase.ddcp.b(Unknown Source)
    at com.ddtek.jdbc.hivebase.ddcp.a(Unknown Source)
    at com.ddtek.jdbc.hivebase.ddco.b(Unknown Source)
    at com.ddtek.jdbc.hivebase.ddco.a(Unknown Source)
    at com.ddtek.jdbc.hive.HiveImplConnection.b(Unknown Source)
    at com.ddtek.jdbc.hivebase.BaseConnection.b(Unknown Source)
    at com.ddtek.jdbc.hivebase.BaseConnection.k(Unknown Source)
    at com.ddtek.jdbc.hivebase.BaseConnection.b(Unknown Source)
    at com.ddtek.jdbc.hivebase.BaseConnection.a(Unknown Source)
    at com.ddtek.jdbc.hivebase.BaseDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at hivejdbcconnection.HiveJdbcConnection.main(HiveJdbcConnection.java:33)
Java Result: 1
like image 668
PMR Avatar asked Mar 31 '15 06:03

PMR


1 Answers

To get hive username and password, go to hive-site.xml and search for javax.jdo.option.ConnectionUserName and javax.jdo.option.ConnectionPassword. The values of these properties are your hive username and password respectively.

(Default values are APP and mine for username and password which can be found in hive-default.xml)

In case, if you don't have such property in hive-site.xml. Then add these lines in hive-site.xml:

<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>hiveuser</value>
</property>
<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>hivepass</value>
</property>
<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
</property>
<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://localhost:3306/hadoop</value>
</property>

Note: I have a database named hadoop in mysql for hive. Thats why the value for javax.jdo.option.ConnectionURL is jdbc:mysql://localhost:3306/hadoop.

After setting or finding your username and password, use it as follows:

Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "hiveuser", "hivepass");

Use your hive database name instead of default. Hope it helps!!!!

like image 159
Rajesh N Avatar answered Oct 20 '22 20:10

Rajesh N