Cloudera上的Java应用程序和数据库之间的连接

时间:2017-02-14 23:36:14

标签: java jdbc hive

作为标题,我对Java应用程序与在虚拟机Cloudera上创建的数据库之间的连接存在问题。

我放置的示例项目应用程序包含连接所需的扩展名为.jar的文件。

虚拟机网卡设置为仅限主机。 这个虚拟机:192.168.56.1。

我不知道下一步该做什么才能对数据库执行查询。

请帮助并抱歉我的英语。

Java代码:

package p;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Scanner;


public class p{
    static Connection connection = null;
    static Statement statement = null;
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Class.forName("com.cloudera.hive.jdbc4.HS2Driver");
        connection = DriverManager.getConnection("jdbc:hive2://192.168.56.1:10000/przychodnia", "cloudera", "cloudera");
        statement = connection.createStatement();
        System.out.println("Wybierz");
        System.out.println("0 aby dodać do istniejącej tabeli wiersz");
        System.out.println("1 aby usunąć z istniejącej tabeli wiersz");
                String SQL = "SELECT * FROM pacjenci";
                ResultSet rs = statement.executeQuery(SQL);

                while (rs.next()){
                    String imie = rs.getString("imie");
                    String p = imie;
                    System.out.println(p);
    }
    }
}

警告:

log4j:WARN No appenders could be found for logger (org.apache.thrift.transport.TSaslTransport).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.sql.SQLException: [Simba][HiveJDBCDriver](500310) Invalid operation: java.net.ConnectException: Connection refused: connect;
    at com.cloudera.hive.hivecommon.api.HiveServer2ClientFactory.createTransport(HiveServer2ClientFactory.java:224)
    at com.cloudera.hive.hive.api.ExtendedHS2Factory.createClient(ExtendedHS2Factory.java:38)
    at com.cloudera.hive.hivecommon.core.HiveJDBCConnection.connect(HiveJDBCConnection.java:597)
    at com.cloudera.hive.jdbc.common.BaseConnectionFactory.doConnect(BaseConnectionFactory.java:219)
    at com.cloudera.hive.jdbc.common.AbstractDriver.connect(AbstractDriver.java:216)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
Caused by: com.cloudera.hive.support.exceptions.GeneralException: [Simba][HiveJDBCDriver](500310) Invalid operation: java.net.ConnectException: Connection refused: connect;
    ... 7 more
Caused by: org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused: connect
    at org.apache.thrift.transport.TSocket.open(TSocket.java:185)
    at org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:248)
    at org.apache.thrift.transport.TSaslClientTransport.open(TSaslClientTransport.java:37)
    at com.cloudera.hive.hivecommon.api.HiveServer2ClientFactory.createTransport(HiveServer2ClientFactory.java:210)
    at com.cloudera.hive.hive.api.ExtendedHS2Factory.createClient(ExtendedHS2Factory.java:38)
    at com.cloudera.hive.hivecommon.core.HiveJDBCConnection.connect(HiveJDBCConnection.java:597)
    at com.cloudera.hive.jdbc.common.BaseConnectionFactory.doConnect(BaseConnectionFactory.java:219)
    at com.cloudera.hive.jdbc.common.AbstractDriver.connect(AbstractDriver.java:216)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at p.p.main(p.java:15)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at org.apache.thrift.transport.TSocket.open(TSocket.java:180)
    ... 10 more

JARS

enter image description here

1 个答案:

答案 0 :(得分:0)

  

这个虚拟机:192.168.56.1。

您的图片显示"未找到列名称"正在使用IP

192.168.56.101