'Access Hive Data from Java

I need to acces the data in Hive, from Java.According to the documentation for Hive JDBC Driver,the current JDBC driver can only be used to query data from default database of Hive.

Is there a way to access data from a Hive database other than the default one , through Java?



Solution 1:[1]

For example, you have a hive table:

create table visit (
    id                int,
    url               string,
    ref              string
)
partitioned by (date string)

Then you can use the statement

INSERT OVERWRITE DIRECTORY '/tmp/hdfs_out' SELECT * FROM  visit WHERE date='2013-05-15';

to load the data to the hdfs then write a mapred job to handle it. Or you can use the statement

INSERT OVERWRITE LOCAL DIRECTORY '/tmp/hdfs_out' SELECT * FROM  visit WHERE date='2013-05-15';

to load the data to the local file system and write a normal java program to handle it.

Solution 2:[2]

The JDBC documentation is found in Hive confluence documentation. For using the JDBC driver you need to have an access by a hive server.

But there are other possibilities to access the data... This all depends on your setup. You could for example also use spark assuming the Hive config and hadoop configs are set appropriately.

the JDBC documentation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jerry_sjtu
Solution 2 user1102074