我正在尝试使用slick在文件上创建H2数据库,并使用SQL Workbench / J打开该文件以进行进一步的查询处理。我在IntelliJ项目中使用下面的文件,似乎它成功创建了一个t.mv.db文件,看起来像是一个M表。但是在尝试在SQL Workbench / J中连接它之后,我得到了这些错误(现在就去研究它们):
TABLE()
Syntax error in SQL statement "TABLE[*]()"; expected "TRUNCATE, {"; SQL statement:
TABLE() [42001-191] [SQL State=42001, DB Errorcode=42001]
SELECT * FROM M
Table "M" not found; SQL statement:
SELECT * FROM M [42102-191] [SQL State=42S02, DB Errorcode=42102]my
有人可以帮助我创建一个可以使用SQL Workbench / J打开的持久H2数据库文件吗?
主要的scala文件:
import slick.driver.H2Driver.api._
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
final case class Message(sender:String, content:String)
final class MessageTable(tag: Tag) extends Table[Message](tag, "M") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def sender = column[String]("sender")
def content = column[String]("content")
def * = (sender, content) <>(Message.tupled, Message.unapply)
}
object Curator {
def main(args: Array[String]) {
final case class Message(sender: String, content: String)
val db = Database.forConfig("h2file")
lazy val messages = TableQuery[MessageTable]
Await.ready(db.run(messages.schema.create),2 seconds)
db.close()
}
}
我的application.conf:
h2file = {
connectionPool = disabled
url = "jdbc:h2:~/scala/workspace/Curator/t"
driver = "org.h2.Driver"
keepAliveConnection = true
}
我的build.sbt:
name := "Curator"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "3.1.0",
"com.h2database" % "h2" % "1.4.185",
"ch.qos.logback" % "logback-classic" % "1.1.2"
)
SQL Workbench / J设置:
Driver: H2 Database Engine (org.h2.Driver)
URL: jdbc:h2:~/scala/workspace/Curator/t"
我还通过“管理驱动程序”链接到下载的h2-latest.jar