【问题标题】:PSQLException: database does not exist SlickPSQLException:数据库不存在 Slick
【发布时间】:2017-11-12 08:45:35
【问题描述】:

我正在学习 Slick,我试图在我的 Intellij IDEA 项目中连接到 PostgreSQL 数据库。如果相关,我在 Ubuntu 14.04 上运行它。每次我运行我的应用程序时都会出现异常:org.postgresql.Driver connect 严重:连接错误: org.postgresql.util.PSQLException: FATAL: 数据库“歌曲”不存在

这是我的代码:

import slick.jdbc.PostgresProfile.api._
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

object Main {

  case class Song(
    id: Int,
    name: String,
    singer: String)

  class SongsTable(tag: Tag) extends Table[Song](tag, "songs") {
    def id = column[Int]("id")

    def name = column[String]("name")

    def singer = column[String]("singer")

    def * = (id, name, singer) <> (Song.tupled, Song.unapply)
  }

  val db = Database.forConfig("scalaxdb")

  val songs = TableQuery[SongsTable]

  def main(args: Array[String]): Unit = {
    Await.result({
      db.run(songs.result).map(_.foreach(row =>
        println("song with id " + row.id + " has name " + row.name + " and a singer is " + row.singer)))
    }, 1 minute)
  }
}

application.conf 文件:

scalaxdb = {
  dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
  properties = {
    driver = "org.postgresql.Driver"
    url = "jdbc:postgresql://localhost/songs?user=user&password=password"
  }
}

build.sbt 文件:

name := "slick-test"

version := "0.1"

scalaVersion := "2.12.4"

libraryDependencies += "com.typesafe.slick" %% "slick" % "3.2.1"
libraryDependencies += "org.slf4j" % "slf4j-nop" % "1.7.25"
libraryDependencies += "com.typesafe.slick" %% "slick-hikaricp" % "3.2.1"
libraryDependencies += "org.postgresql" % "postgresql" % "42.1.4"

如果有人帮我找出错误,我将不胜感激!

【问题讨论】:

    标签: postgresql intellij-idea slick intellij-14


    【解决方案1】:

    显然,我在另一个数据库(不是我试图连接的数据库)中创建了我的“歌曲”关系。这就是它无法连接的原因。现在一切正常!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 2013-12-13
      • 2011-01-03
      • 1970-01-01
      相关资源
      最近更新 更多