Created 08-22-2017 04:01 PM
I have tried the below sample code from Phoenix website by copying the phoenix client jar from /usr/hdp/current/phoenix-client in my server. I tried running it locally as well as on the server, but i keep getting the below error:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:phoenix:zk1,zk2,zk3:2181:/hbase-unsecure
Are there any other prerequisites other than including the client jar in the code to connect to phoenix?
PS: I had no problems connecting to phoenix from command line.
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.PreparedStatement; import java.sql.Statement; public class test { public static void main(String[] args) throws SQLException { Statement stmt = null; ResultSet rset = null; Connection con = DriverManager.getConnection("jdbc:phoenix:zk1,zk2,zk3:2181:/hbase-unsecure"); 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 test"); rset = statement.executeQuery(); while (rset.next()) { System.out.println(rset.getString("mycolumn")); } statement.close(); con.close(); } }
Created 08-22-2017 04:51 PM
If you want to connect using Phoenix APIs (phoenix URL"jdbc:phoenix:") then you will have to load Driver Class of type "
"org.apache.phoenix.jdbc.PhoenixDriver"
import org.apache.phoenix.jdbc.PhoenixDriver; Class.forName("org.apache.phoenix.jdbc.PhoenixDriver"); Statement stmt = null; ResultSet rset = null; Connection con = DriverManager.getConnection("jdbc:phoenix:zk1,zk2,zk3:2181:/hbase-unsecure");
.
Created 08-22-2017 04:55 PM
Created 08-22-2017 05:24 PM
@Jay SenSharma Is it possible to connect to phoenix on server from local machine?
Created 08-24-2017 06:31 AM
You need phoenix-client libs in classpath for remote PQS connection.