1
votes

I am connecting to azure sql server from databricks and for that i am using jdbc connector

val jdbcUsername = "user1"
val jdbcPassword = "pwd1"
val jdbcHostname = "XXXXsqldevussc.database.windows.net" 
val jdbcPort = 1111
val jdbcDatabase ="XXXXacttrackdev"

I am creating the jdbc url as follows

import java.util.Properties

val jdbc_url = s"jdbc:sqlserver://${jdbcHostname}:${jdbcPort};database=${jdbcDatabase};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=60;"
val connectionProperties = new Properties()
connectionProperties.put("user", s"${jdbcUsername}")
connectionProperties.put("password", s"${jdbcPassword}")  
val cP = connectionProperties

val driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
connectionProperties.setProperty("Driver", driverClass)

This is all in a notebook in a common folder and now i want to pass these values to a notebook in the project folder. Using dbutils.notebook.exit i am able to just pass one value (jdbc_url), but i need to pass connectionProperties as well to other notebook. Can somebody help me in doing this. I am trying to pass both the values in 2 separate dbutils.notebook.exit, but i get an error

dbutils.notebook.exit(jdbc_url) // works well
dbutils.notebook.exit(cP) //throws an error command-2330564045697042:1: error: type mismatch;
                          // found   : java.util.Properties 
                          // required: String
                          // dbutils.notebook.exit(cP)

How do i pass both the values using dbutils.notebook.exit. Thanks for the help

Thanks !

1
Any help will be greatly appreciated - Sujatha

1 Answers

0
votes

You are trying to return java.util.Properties object using dbutils.notebook.exit. However, dbutils.notebook.exit only supports String.

So you might need to convert Properties object to String. Something like:

    public static String getPropertyAsString(Properties prop) {    
      StringWriter writer = new StringWriter();
      prop.list(new PrintWriter(writer));
      return writer.getBuffer().toString();
    }

    dbutils.notebook.exit(getPropertyAsString(cP))   

You can read back String into Properties object in other notebook.