How to establish a Microsoft azure databricks delta tables connection using spring boot just like mysql,sql server

Viewed 663

Hi I want to establish a connection with the Microsoft azure databricks delta table inside my spring boot application.I have the cluster url,username and the password(token) of the delta table from which I need to pull the data to my application. Kindly shed some light on this

1 Answers

You can access cluster & underlying tables using the JDBC (see documentation). You need to get the corresponding driver, and add it to your application, and then just use normal JDBC API, like this:

String jdbcConnectPassthroughCluster = "jdbc:spark://<server-hostname>:443/default;transportMode=http;ssl=1;httpPath=sql/protocolv1/o/0/xxxx-xxxxxx-xxxxxxxx;AuthMech=3;UID=token;PWD=";

String PATH = "<personal token>"
String JDBC_DRIVER = "com.simba.spark.jdbc.Driver";
String DB_URL = jdbcConnectPassthroughCluster + PAT;

Class.forName(JDBC_DRIVER);
System.out.println("Getting connection");
Connection conn = DriverManager.getConnection(DB_URL);
Statement stmt = conn.createStatement();
System.out.println("Going to execute query");
ResultSet rs = stmt.executeQuery("select * from table");
System.out.println("Query is executed");
int i = 0;
while(rs.next()) {
    System.out.println("Row " + i + "=" + rs.getLong(1));
    i++;
}
rs.close();
stmt.close();
conn.close();
Related