I'm new with Hadoop and the ecosystem. I'm trying Hive with JDBC in Java. This is my simple code only to test the driver:
我是Hadoop和生态系统的新手。我在用JDBC Java尝试Hive。这是我用来测试驱动程序的简单代码:
import java.sql.DriverManager;
import java.sql.SQLException;
public class PrepareHiveTable {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName(driverName);
Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", "");
}
}
I've imported org.apache.hive.jdbc.HiveDriver
to the classpath and this is the driver list on my DriverManager
:
我进口org.apache.hive.jdbc。HiveDriver指向类路径,这是驱动程序管理器的驱动列表:
org.apache.calcite.avatica.remote.Driver@45ff54e6
org.apache.calcite.jdbc.Driver@3581c5f3
org.apache.derby.jdbc.AutoloadedDriver40@4f8e5cde
com.mysql.jdbc.Driver@6f75e721
org.apache.hive.jdbc.HiveDriver@69222c14
But when I run the code I get this error:
但是当我运行代码时,我得到了这个错误:
Exception in thread "main" java.sql.SQLException: No suitable driver found for
jdbc:hive://localhost:10000/default
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at PrepareHiveTable.main(PrepareHiveTable.java:24)
Java Result: 1
Anyone here know how can it happen? And how to solve it?
这里有人知道这是怎么发生的吗?怎么解呢?
2 个解决方案
#1
19
I found the solution. I use hive 1.2.1 so I need to write jdbc:hive2://localhost:10000/default
instead of jdbc:hive://localhost:10000/default
我找到了解决方案。我使用了hive 1.2.1,所以我需要编写jdbc:hive2:/ localhost:10000/default,而不是jdbc:hive://localhost:10000/default
thank you
谢谢你!
#2
1
I'm using hive-jdbc-1.0.0.jar
and I got the connection established successfully to hive db. I'm also sharing other details which I used here.
我用hive-jdbc-1.0.0。jar和我成功地建立了与hive db的连接。我还分享了我在这里用到的其他细节。
Driver Name: org.apache.hive.jdbc.HiveDriver
URL: ("jdbc:hive2://localhost:10000/default","username","password")
司机的名字:org.apache.hive.jdbc。HiveDriver URL:(" jdbc:hive2:/ / localhost:10000 /违约”,“用户名”,“密码”)
Below are the total jars I used for my project to work on hive db from my java project.
下面是我在java项目中用于处理hive db的所有jar。
#1
19
I found the solution. I use hive 1.2.1 so I need to write jdbc:hive2://localhost:10000/default
instead of jdbc:hive://localhost:10000/default
我找到了解决方案。我使用了hive 1.2.1,所以我需要编写jdbc:hive2:/ localhost:10000/default,而不是jdbc:hive://localhost:10000/default
thank you
谢谢你!
#2
1
I'm using hive-jdbc-1.0.0.jar
and I got the connection established successfully to hive db. I'm also sharing other details which I used here.
我用hive-jdbc-1.0.0。jar和我成功地建立了与hive db的连接。我还分享了我在这里用到的其他细节。
Driver Name: org.apache.hive.jdbc.HiveDriver
URL: ("jdbc:hive2://localhost:10000/default","username","password")
司机的名字:org.apache.hive.jdbc。HiveDriver URL:(" jdbc:hive2:/ / localhost:10000 /违约”,“用户名”,“密码”)
Below are the total jars I used for my project to work on hive db from my java project.
下面是我在java项目中用于处理hive db的所有jar。