Search code examples
mysqlscalaamazon-web-servicesslick

Connecting to an AWS MySQL Database from Scala with Slick


i just created my first AWS MySQL Database and want to connect to that from my scala application using Slick.

My config file shows:

awsMySQL = {
profile = "slick.jdbc.MySQLProfile$"
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
  properties = {
    url = "jdbc:mysql://<databaseName>.cn17tbad2awy.eu-central-1.rds.amazonaws.com"
    user = "foo"
    password = "bar"
   driver = com.mysql.cj.jdbc.Driver
  }
connectionPool = disabled
keepAliveConnection = true
}

I just define a query to receive all my customers, but when exeuting this code i receive a SQLException: No database selected.

val db = Database.forConfig("awsMySQL")

val CustomersDAO = TableQuery[Customers]
val q1 = for (c <- CustomersDAO) yield c.name
val a = q1.result
val f = db.run(a)

Await.result(f, Duration.Inf)

I do not really understand this exception, because from my point of view by the url specifies the database. Could you please help me.

Thanks in advance.


Solution

  • I think you are pointing to the host where the MySQL service is running but not to the Database itself

    Try to replace url = "jdbc:mysql://<databaseName>.cn17tbad2awy.eu-central-1.rds.amazonaws.com" with something like:

    url = "jdbc:mysql://<databaseName>.cn17tbad2awy.eu-central-1.rds.amazonaws.com/DBSCHEMA"