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

时间:2019-06-06 21:59:25

标签: java scala azure azure-databricks delta

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

我尝试连接simba驱动程序,但是我很难获取驱动程序的类名和url配置。

任何解决方案都值得赞赏。 我不能在此处粘贴代码作为其公司代码。

谢谢。

1 个答案:

答案 0 :(得分:1)

在下面检查此链接。这具有使用JDBC配置增量的步骤

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()
    }
}