java.sql.SQLException: No suitable driver found fo

2019-04-21 05:03发布

问题:

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:

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.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?

回答1:

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

thank you



回答2:

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.

Driver Name: org.apache.hive.jdbc.HiveDriver
URL: ("jdbc:hive2://localhost:10000/default","username","password")

Below are the total jars I used for my project to work on hive db from my java project.