Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

JDBC Connection to phoenix failed

JDBC Connection to phoenix failed

New Contributor

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();
	}
}
4 REPLIES 4

Re: JDBC Connection to phoenix failed

Super Mentor

@ROHIT AILA

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");

.

Re: JDBC Connection to phoenix failed

Super Mentor

Re: JDBC Connection to phoenix failed

New Contributor

@Jay SenSharma Is it possible to connect to phoenix on server from local machine?

Highlighted

Re: JDBC Connection to phoenix failed

Contributor

You need phoenix-client libs in classpath for remote PQS connection.

Don't have an account?
Coming from Hortonworks? Activate your account here