Connecting to apache phoenix using JDBC and Java -
i have small java program in try establish connection remote phoenix server have running.
package jdbc_tests; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; public class phoenixtest { static final string jdbc_driver = "org.apache.phoenix.jdbc.phoenixdriver"; static final string ip = "<placeholder>" static final string port = "<placeholder>" static final string db_url = "jdbc:phoenix://" + ip + ":" + port + "/"; public static void main(string[] args) { connection conn = null; statement st = null; try { class.forname("org.apache.phoenix.jdbc.phoenixdriver"); system.out.println("connecting database.."); conn = drivermanager.getconnection(db_url); system.out.println("creating statement..."); st = conn.createstatement(); string sql; sql = "select distinct did sensor_data"; resultset rs = st.executequery(sql); while(rs.next()) { string did = rs.getstring(1); system.out.println("did found: " + did); } rs.close(); st.close(); conn.close(); } catch (sqlexception se) { se.printstacktrace(); } catch (exception e) { // handle errors class.forname e.printstacktrace(); } { // block used close resources try { if (st != null) st.close(); } catch (sqlexception se2) { } // nothing can try { if (conn != null) conn.close(); } catch (sqlexception se) { se.printstacktrace(); } // end try } // end try system.out.println("goodbye!"); } }
when try run program get:
java.sql.sqlexception: no suitable driver found jdbc:phoenix://<ip>:<port>/
i have added following jar apache phoenix distribution:
phoenix-4.9.0-hbase-1.2-client.jar
which matches phoenix , hbase vesions.
what doing wrong?
i think missing name of database , url seams not correct:
"jdbc:phoenix://" + ip + ":" + port + "/" + db_name //--------------------------------------------^^
you have try url instead :
connection con = drivermanager.getconnection("jdbc:phoenix:<ip>:<port>:/<db_name>");
Comments
Post a Comment