首页 > 解决方案 > 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.

标签: mysqlscalaamazon-web-servicesslick

解决方案


我认为您指向的是运行 MySQL 服务的主机,而不是数据库本身

尝试url = "jdbc:mysql://<databaseName>.cn17tbad2awy.eu-central-1.rds.amazonaws.com"用类似的东西替换:

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

推荐阅读