phoenix jdbc doesn't work, no exceptions and stuck

烈酒焚心 提交于 2020-01-06 18:08:04

问题


I'm new to phoenix and hbase.hbase table and phoenix view works well and i can fetch data through phoenix. when I access jdbc to phoenix,it stucks.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Phoenix {
    private static String driver = "org.apache.phoenix.jdbc.PhoenixDriver";
    public static void main(String[] args) throws SQLException {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Statement stmt = null;
        ResultSet rs = null;
        System.out.println("start...");
        Connection con = DriverManager.getConnection("jdbc:phoenix:[my_cloud_server_ip]:2181");
        System.out.println(con);
        con.close();
    }
}

(only one zookeeper server has public internet ip,so i write this ip there,does it matters?)

it prints "start..." and no response any more

BUT when when the url is "jdbc:phoenix:ip:2181" or "jdbc:phoenix:ip:2181/hbase"

i got no response

when i add some other words ,for example "jdbc:phoenix:ip:2181/balabala"

i got NULL POINTER EXCEPTION

why ?

I hope u can understand what i say:)


回答1:


Reproducing your example, I am getting a java.net.SocketTimeoutException after 60 seconds, caused by java.net.UnknownHostException: unknown host: <hostname_of_my_zk_server>. But maybe that's what you called "no response" if you were in a hurry (or if you have a custom hbase-site.xml with a larger timeout client-side).

This error seems like the one explained in this article (section Zookeeper at the end) :

As in our case CDH was running in a test VM, we encountered this issue: http://stackoverflow.com/questions/18428722/hbase-java-client-unknown-host-localhost-localdomain

That was worked around by adding localhost.localdomain to the existing /etc/hosts entry for cluster1, which was already pointing to the right IP address.

This answer on SO summarizes the solution.

Basically, you need to add an entry to your /etc/hosts client-side :

<my_cloud_server_ip> <hostname_of_my_cloud_server_ip>

Moreover, you need to have an hbase-site.xml client-side (you can use the one on your server as a basis).



来源:https://stackoverflow.com/questions/51498170/phoenix-jdbc-doesnt-work-no-exceptions-and-stuck

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!