【问题标题】:Scala Slick connection to MySQL database using InteliJ-IDEScala Slick 使用 IntelliJ-IDEA 连接 MySQL 数据库
【发布时间】:2017-08-15 02:26:08
【问题描述】:

如何在 InteliJ IDE 上使用 Scala Slick 库连接到 MySQL 数据库? 找不到任何例子。我可以通过下面的示例成功连接到 PostgreSQL 数据库,但是有什么想法可以连接到 MySQL 或 SQLite 吗?

    def main(args: Array[String]): Unit = {

        val connectionUrl = "jdbc:postgresql://localhost/scala_test?user=postgres&password=kurmis"
        println("Postgresql oppened ")

        Database.forURL(connectionUrl, driver = "org.postgresql.Driver") withSession {
          implicit session =>
val users = TableQuery[testas]
        for (a <- 1 to 100) {
          val r = scala.util.Random
users.map(u => (u.nr, u.pirmas, u.antras, u.trecias, u.ketvirtas, u.penktas, u.sestas, u.septinas, u.astuntas, u.devintas)
      )+= (a, r.nextInt.toString, r.nextInt.toString, r.nextInt.toString, r.nextInt.toString,
        r.nextInt.toString, r.nextInt.toString, r.nextInt.toString, r.nextInt.toString, r.nextInt.toString)
    }

【问题讨论】:

    标签: mysql database scala intellij-idea slick


    【解决方案1】:

    我正在使用

    运行我的 Slick-Play 应用程序

    application.conf

    mysql {
      slick.driver=scala.slick.driver.MySQLDriver
      driver=com.mysql.cj.jdbc.Driver
      url="jdbc:mysql://localhost:3306/MYDBNAME?autoReconnect=true&useSSL=false"
      user=""
      password=""
    }
    

    确保您已将 mysql-connector-java 包含为 sbt 依赖项

    然后在我的应用中我使用:

    val db = Database.forConfig("mysql")
    

    【讨论】:

      猜你喜欢
      • 2018-04-24
      • 1970-01-01
      • 2020-06-19
      • 2022-12-18
      • 1970-01-01
      • 1970-01-01
      • 2015-08-19
      • 2020-08-02
      • 1970-01-01
      相关资源
      最近更新 更多