相关文章推荐
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a scenario where I need to trigger Stored procedure in the SQL server from Databricks. With the spark SQL connector,I can able to SELECT but not trigger the stored procedure.

I am trying to connect Java JDBC but whenever I execute it says "NO Driver found"

I have uploaded the driver (mssql_jdbc_8_2_2_jre11.jar) to the Databricks cluster.

  • Tried Code:

    import java.sql.{Connection, DriverManager, ResultSet}

    DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")

    val conn = DriverManager.getConnection("jdbc:xxxx.database.windows.net;databaseName=yyyy-db;user=admin;password=pwd;useUnicode=true;characterEncoding=UTF-8")

    Error: java.sql.SQLException: No suitable driver found

    Need suggestion on the same and is there a way to execute stored procedure from Databricks using Scala / Java.

    I have uploaded the driver (mssql_jdbc_8_2_2_jre11.jar) to the Databricks cluster.

    That shouldn't be necessary and may be the cause of your problem. It's already included in the Databricks runtime, as documented in the release notes .

    Or more likely your url just messed up. You can copy-and-paste from the connection string settings in the Azure portal. Should be something like:

    jdbc:sqlserver://xxxxxx.database.windows.net .. .

    This works for me:

    %scala
    import java.util.Properties
    import java.sql.DriverManager
    val jdbcUsername = dbutils.secrets.get(scope = "kv", key = "sqluser")
    val jdbcPassword = dbutils.secrets.get(scope = "kv", key = "sqlpassword")
    val driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    // Create the JDBC URL without passing in the user and password parameters.
    val jdbcUrl = s"jdbc:sqlserver://xxxxxx.database.windows.net:1433;database=AdventureWorks;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;"
    val connection = DriverManager.getConnection(jdbcUrl, jdbcUsername, jdbcPassword)
    val stmt = connection.createStatement()
    val sql = """
    exec usp_someproc ...
    stmt.execute(sql)
    connection.close()
    

    Also this

    %scala
    import java.sql.{Connection, DriverManager, ResultSet}
    DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
                    Thank you so much for this post. I'm new to Java / Scala / Spark / Databricks and this info so much harder to find than expected. This works, it should be marked as the solution.
    – Dudeman3000
                    Nov 20, 2020 at 18:05
                    I don't see that the inclusion of the driver is mentioned anywhere in the release notes. Can you point out where it is mentioned?
    – HansHarhoff
                    Oct 19, 2022 at 7:35
                    Earlier versions enumerated the Java libraries that they ship in each version.  Looks like they discontinued that.  But that JDBC library is still there and it’s a dependency for the Synapse Spark driver.
    – David Browne - Microsoft
                    Oct 19, 2022 at 11:30
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

  •  
    推荐文章