如何使用 JDBC 驱动程序连接到 Databricks Delta 表

sri*_*u p 6 java scala azure azure-databricks delta-lake

如何使用 JDBC 连接到 Databricks Delta 表?

我尝试过连接 simba 驱动程序,但我在驱动程序类名称和 url 配置方面遇到了困难。

任何解决方案表示赞赏。我无法在此处粘贴代码作为其公司代码。

提前致谢。

dil*_*rma 2

检查下面的这个链接。其中包含使用 JDBC 配置 delta 的步骤

http://sedeks.blogspot.com/2019/05/how-to-connect-to-databricks-delta.html

此链接中提供的代码:

    import java.sql.DriverManager 
import java.sql.Driver
import java.sql.Connection 
import javax.sql.DataSource

object ScalaJdbcConnectSelect {
    def main(args: Array[String]) {
        val driver = "com.simba.spark.jdbc41.Driver"  //attach the Spark jar to the Classpath.
        val url = "jdbc:spark://field-eng.cloud.databricks.com:443/default;transportMode=http;ssl=true;httpPath=sql/protocolvl/o/0/0911-153027-hopes19";    
        val username = "token" 
        val password = "<token-value>" //Token generated from databricks profile page.
        var connection:Connection = null
        try {
        // Create the connection
            Class.forName(driver)
            connection = DriverManager.getConnection(url, username, password)
            if(connection != null){
                println("Connection Established");

            }
            else {
                println("Connection Failed");
            }
            // create the statement
            val statement = connection.createStatement()
            val resultSet = statement.executeQuery("<<Query>") // Profile your query here.
            while ( resultSet.next() ) {
                // Iterate through Result set
            } 
        catch {
            case e => e.printStackTrace
        }
        connection.close()
    }
}
Run Code Online (Sandbox Code Playgroud)