Ich habe ein kleines Java-Programm, in dem ich versuche, eine Verbindung zu einem Remote-Phoenix-Server, den ich ausgeführt habe, herzustellen.Verbinden mit Apache Phoenix mit JDBC und Java
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 to database..");
conn = DriverManager.getConnection(DB_URL);
System.out.println("Creating statement...");
st = conn.createStatement();
String sql;
sql = "SELECT DISTINCT did FROM 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 for Class.forName
e.printStackTrace();
} finally {
// finally block used to close resources
try {
if (st != null)
st.close();
} catch (SQLException se2) {
} // nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
} // end finally try
} // end try
System.out.println("Goodbye!");
}
}
Wenn ich versuche, mein Programm laufen zu lassen, erhalte ich:
java.sql.SQLException: No suitable driver found for jdbc:phoenix://<ip>:<port>/
Ich habe das folgende Glas aus der Apache Phoenix Distribution hinzugefügt:
phoenix-4.9.0-HBase-1.2-client.jar
die mein Phoenix und Hbase Spiele vesions .
Was mache ich falsch?
Ihre URL ist falsch: Sie sollte das '//' entfernen. Siehe auch http://phoenix.apache.org/ –
Mögliches Duplikat von [Die berüchtigte java.sql.SQLException: Kein passender Treiber gefunden] (http://stackoverflow.com/questions/1911253/the-infamous-java-sql -sqlexception-no-pretty-driver-found) –
@PrajjwalSrivastav Ich suppegree – Zeliax