Connect from Java to Hive using JDBC Connect from Java to Hive using JDBC hadoop hadoop

Connect from Java to Hive using JDBC


Try

private static String driverName = "org.apache.hive.jdbc.HiveDriver"

instead of

private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";

I hope you have added Class.forName(driverName) statement in your code


I think in your question you said its Hive server 1. If so the driver name and connection string should be as follows:

"org.apache.hadoop.hive.jdbc.HiveDriver"jdbc:hive://localhost:10000/default", "", "")

If you are using Hive server 2 , then it should be as follows:

org.apache.hive.jdbc.HiveDriverjdbc:hive2://<host>:<port>/<db>

I have used the same sample as you given and I am able to connect Hive with following dependencies in my pom.xml

   <dependency>        <groupId>org.apache.hive</groupId>        <artifactId>hive-metastore</artifactId>        <version>0.12.0-cdh5.0.0</version>    </dependency>    <dependency>        <groupId>org.apache.hive</groupId>        <artifactId>hive-service</artifactId>        <version>0.12.0-cdh5.0.0</version>    </dependency>    <!-- runtime Hive -->    <dependency>        <groupId>org.apache.hive</groupId>        <artifactId>hive-common</artifactId>        <version>0.12.0-cdh5.0.0</version>        <scope>runtime</scope>    </dependency>    <dependency>        <groupId>org.apache.hive</groupId>        <artifactId>hive-beeline</artifactId>        <version>0.12.0-cdh5.0.0</version>        <scope>runtime</scope>    </dependency>    <dependency>        <groupId>org.apache.hive</groupId>        <artifactId>hive-jdbc</artifactId>        <version>0.12.0-cdh5.0.0</version>        <scope>runtime</scope>    </dependency>    <dependency>        <groupId>org.apache.hive</groupId>        <artifactId>hive-shims</artifactId>        <version>0.12.0-cdh5.0.0</version>        <scope>runtime</scope>    </dependency>    <dependency>        <groupId>org.apache.hive</groupId>        <artifactId>hive-serde</artifactId>        <version>0.12.0-cdh5.0.0</version>        <scope>runtime</scope>    </dependency>    <dependency>        <groupId>org.apache.hive</groupId>        <artifactId>hive-contrib</artifactId>        <version>0.12.0-cdh5.0.0</version>        <scope>runtime</scope>    </dependency>    <dependency>


u need to change on two places

use this

private static String driverName = "org.apache.hive.jdbc.HiveDriver"

instead of

private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";

and second is use this

jdbc:hive2://localhost:10000/default", "", ""

instead of

jdbc:hive://localhost:10000/default", "", ""