2

I'm connecting to an Azure database with the azure-sqldb library for Spark.

In the GitHub example, they define the log-in credentials in the code. I'm relatively new to Scala, and I'm used to R Studio where I can just have the GUI prompt me for passwords, eg:

password <- rstudioapi::askForPassword("Please enter your password")

Whats the best way to achieve something similar in Scala and IntelliJ? The goal is to keep login credentials away from the code, and preferably only have to enter them once per session (not every time I run the code).

Current code:

object dev extends SparkSessionWrapper {

  def main(args: Array[String]): Unit = {
    println(data.head())
    spark.stop()
  }

  val statsDB = Config(Map(
    "url" -> "my.database.url",
    "databaseName" -> "myDB",
    "dbTable" -> "myTable",
    "user" -> "myLogin",
    "password" -> "myPWD",
    "connectTimeout" -> "600",
    "queryTimeout" -> "12000"
  ))

  val data: DataFrame = spark.read.sqlDB(statsDB)
}
djfinnoy
  • 585
  • 3
  • 13

1 Answers1

0

You can use Java libraries in Scala. I tried JOptionPane. Like here: JOptionPane to get password It is under javax.swing library which is part of any standard Java SE installation, so there is no need to add a dependency. You only need the scala-swing dependency:

libraryDependencies += "org.scala-lang" % "scala-swing" % scalaVersion.value
Liza Shakury
  • 670
  • 9
  • 20