Created 10-05-2017 09:22 AM
Hi guys,
I followed some tutorials with adding hbase client jar and phoenix client jar, and I'm not to connect and execute my query. Can anyone give me some leeds.
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class Test { public static void main(String[] args) throws SQLException { // Statement stmt = null; ResultSet rset = null; try { Class.forName("org.apache.phoenix.jdbc.PhoenixDriver"); } catch (ClassNotFoundException e1) { System.out.println("Exception Loading Driver"); e1.printStackTrace(); } try { Connection con = DriverManager.getConnection("jdbc:phoenix:localhost:2181:/hbase-unsecure"); // Connection con = // DriverManager.getConnection("jdbc:phoenix:localhost:/hbase-unsecure:./keytab/ISMAEL.keytab:ISMAEL@MOCK"); // stmt = con.createStatement(); // // stmt.executeUpdate("create table test (mykey integer not null // primary key, mycolumn varchar)"); // stmt.executeUpdate("upsert into test values (1,'Hello')"); // stmt.executeUpdate("upsert into test values (2,'World!')"); // con.commit(); PreparedStatement statement = con.prepareStatement("select * from dsp_paas:toto"); rset = statement.executeQuery(); while (rset.next()) { System.out.println(rset.getString("cf1")); } statement.close(); con.close(); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
I have this error message when I execute my code.
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. log4j:WARN No appenders could be found for logger (org.apache.hadoop.util.Shell). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. java.lang.RuntimeException: java.lang.NullPointerException java.sql.SQLException: java.lang.RuntimeException: java.lang.NullPointerException at org.apache.phoenix.query.ConnectionQueryServicesImpl$12.call(ConnectionQueryServicesImpl.java:2482) at org.apache.phoenix.query.ConnectionQueryServicesImpl$12.call(ConnectionQueryServicesImpl.java:2389) at org.apache.phoenix.util.PhoenixContextExecutor.call(PhoenixContextExecutor.java:76) at org.apache.phoenix.query.ConnectionQueryServicesImpl.init(ConnectionQueryServicesImpl.java:2389) at org.apache.phoenix.jdbc.PhoenixDriver.getConnectionQueryServices(PhoenixDriver.java:255) at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.createConnection(PhoenixEmbeddedDriver.java:150) at org.apache.phoenix.jdbc.PhoenixDriver.connect(PhoenixDriver.java:221) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:270) at com.edf.dp.phoenix.Test.main(Test.java:24) Caused by: java.lang.RuntimeException: java.lang.NullPointerException at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:218) at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:327) at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:302) at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:167) at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:162) at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:797) at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:602) at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:366) at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:403) at org.apache.phoenix.query.ConnectionQueryServicesImpl$12.call(ConnectionQueryServicesImpl.java:2417) ... 9 more Caused by: java.lang.NullPointerException at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.getMetaReplicaNodes(ZooKeeperWatcher.java:463) at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:561) at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getMetaRegionLocation(ZooKeeperRegistry.java:61) at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateMeta(ConnectionManager.java:1186) at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1153) at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:300) at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:156) at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:60) at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:210) ... 18 more
Created 10-09-2017 05:52 PM
Hi @Aditya Sirna it's working now using (hbase client, phoenix jars and zookeeper jars. I get them from the hdp directories and I added the hbase_site.xml an core-site.xml in the classpath).
About the url:
"jdbc:phoenix:localhost:2181:/hbase:/keytab/ISMAEL.keytab:ISMAEL@MOCK"
Thanks for your help.
Best regards
Ismael
Created 10-05-2017 10:56 AM
Is the cluster kerberized ? If yes, then the connection string should be "jdbc:phoenix:localhost:2181:/hbase-secure:<keytab path>:<principal>"
ex: "jdbc:phoenix:localhost:2181:/hbase-secure:/keytab/ISMAEL.keytab:ISMAEL@MOCK"
In the commented code , I see that you were using /hbase-unsecure.
Thanks,
Aditya
Created 10-05-2017 11:18 AM
Hi @Aditya SirnaAditya
Thanks for the replay I confirm the cluster is kerberized that's why I tried the two ways with the keytab and without. I still have the same issue.
Best regards
Ismael
Created 10-05-2017 11:23 AM
I am sure that you are using /hbase-secure and not /hbase-unsecure. Can you please check if the zookeeper is active on localhost
netstat -tupln | grep 2181
Can you try passing all the zookeeper quorum nodes. <zk1:2181>,<zk2:2181>..
Also, can you check if you are able to connect to phoenix using some client (ex : sqlline etc)
cd /usr/hdp/current/phoenix-client/bin/ ./sqlline.py localhost:2181:/hbase-secure
Thanks,
Aditya
Created 10-09-2017 05:52 PM
Hi @Aditya Sirna it's working now using (hbase client, phoenix jars and zookeeper jars. I get them from the hdp directories and I added the hbase_site.xml an core-site.xml in the classpath).
About the url:
"jdbc:phoenix:localhost:2181:/hbase:/keytab/ISMAEL.keytab:ISMAEL@MOCK"
Thanks for your help.
Best regards
Ismael
Created 10-10-2017 04:42 AM
Glad that its working for you. Can you please accept the solution. This will be helpful for the community to find the correct answer easily.
-Aditya