从Google DataProc群集连接到Azure SQL时,获取Adal4j/Authentication Exception

发布于 2025-02-11 12:44:12 字数 1591 浏览 0 评论 0原文

请听我说。

我能够使用 apache spark Connector dataproc群集中。但是,在测试时,我有时发现SQL Server数据库不可用,因此,写操作失败了。

因此,我决定添加一个异常逻辑,以检查数据库在写入Azure DB之前是否可用使用以下代码,

    var connection: Connection = null
    val url = "jdbc:sqlserver://***.database.windows.net:1433;databaseName=some_db;encrypt=true;trustServerCertificate=true;authentication=ActiveDirectoryPassword"
    val user = "xxxx"
    val password = ******
    try
          {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
            connection = DriverManager.getConnection(url, user, password)
            log.info(s"Successfully established connection on attempt: "+attempts)
            return
          }

此代码在我的本地计算机中正常工作。但是,尽管在DataProc中运行了相同的操作,但我遇到以下错误,

Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/aad/adal4j/AuthenticationException

我已经走了相似的问题在SO中进行了讨论。但这对我来说有所不同,因为要编写到SQL Server的Apache Spark连接器工作正常。我只想让代码drivermanager.getConnection(url,用户,密码)在我写之前测试连接。

Please hear me out.

I am able to successfully write to Azure SQL server table using Apache Spark connector in Dataproc cluster. But then while testing I found sometime that the SQL server database in not available and because of this the write operation fails.

So, I decided to add an exception logic to check if the database is available or not using the following code before writing to Azure DB,

    var connection: Connection = null
    val url = "jdbc:sqlserver://***.database.windows.net:1433;databaseName=some_db;encrypt=true;trustServerCertificate=true;authentication=ActiveDirectoryPassword"
    val user = "xxxx"
    val password = ******
    try
          {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
            connection = DriverManager.getConnection(url, user, password)
            log.info(s"Successfully established connection on attempt: "+attempts)
            return
          }

This code works fine in my local machine. But while running the same in Dataproc I am getting the below error,

Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/aad/adal4j/AuthenticationException

I already went though this similar issue discussed in SO. But it's bit different for me as the Apache Spark connector to write to SQL server is working fine. I just want to have the code DriverManager.getConnection(url, user, password) work to test the connection before my write.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文