我試圖開始玩和光滑。玩滑動配置
策略;從激活者教程中獲取hello-slick-3.1項目。
如果在內存數據庫中H2能正常工作。我想連接到一個sql服務器。在戰鬥結束後,我有一些使用jdts連接的配置。
在應用程序的.conf
driver=net.sourceforge.jtds.jdbc.Driver
url="jdbc:jtds:sqlserver://%%%%:1433;databaseName=%%%%;user=%%%;password=%%%%%"
這是使用的
com.typesafe.slick.driver.ms.SQLServerDriver
這似乎已經做出故意爲難使用JTDS驅動程序。我還沒有找到一個成功的配置。 JTDS設法根據它的模式創建「供應商」表,但隨後的所有請求都會由於模糊的「數據截斷」信息而崩潰;
object HelloSlick extends App {
val db = Database.forConfig("sqlServerLocal")
try {
// The query interface for the Suppliers table
val suppliers: TableQuery[Suppliers] = TableQuery[Suppliers]
val setupAction: DBIO[Unit] = DBIO.seq(
// Create the schema by combining the DDLs for the Suppliers and Coffees
// tables using the query interfaces
//(suppliers.schema).create,
// Insert some suppliers
suppliers += (101, "Acme, Inc.", "99 Market Street", "Groundsville", "CA", "95199"),
suppliers += (49, "Superior Coffee", "1 Party Place", "Mendocino", "CA", "95460"),
suppliers += (150, "The High Ground", "100 Coffee Lane", "Meadows", "CA", "93966")
)
告訴我,
background log: info: 10:58:48.465 [sqlServerLocal-1] DEBUG slick.jdbc.JdbcBackend.statement - Preparing statement: insert into "SUPPLIERS" ("SUP_ID","SUP_NAME","STREET","CITY","STATE","ZIP") values (?,?,?,?,?,?)
background log: error: Exception in thread "main" java.sql.DataTruncation: Data truncation
有沒有人有什麼想法?用光滑連接到SQL服務器 - 3.1甚至是一個明智的嘗試?
編輯::
@szeiger使得我正在導入錯誤的東西到模型類的優秀點。我從Hello Slick示例中導入了舊的H2驅動程序,應該用此替換它。
import com.typesafe.slick.driver.ms.SQLServerDriver.api._
爲了作爲SQL服務器語言工作。
使這一變化,DB配置這「做了」不再起作用,廣告這個
background log: info: Running HelloSlick
background log: error: Exception in thread "main" java.lang.NoClassDefFoundError: slick/profile/BasicProfile$SimpleQL
我試着改變實際變量的DB相匹配的「推薦」戰略提出的實例後由szeiger。
val db = Database.forURL("jdbc:sqlserver://%%%:1433;user=%%%%;password=%%%%", driver="com.typesafe.slick.driver.ms.SQLServerDriver",
executor = AsyncExecutor("test1", numThreads=10, queueSize=1000))
不幸的是,這樣做失敗了,
background log: error: Exception in thread "main" java.lang.NoClassDefFoundError: slick/profile/BasicProfile$Implicits
與JTDS驅動程序,它與光滑MSSQL司機相同的錯誤消息,儘管我盡了最大努力,我不能實例化MS JDBC驅動程序。它位於應用程序中的一個名爲'lib'的文件夾中,儘管我懷疑這可能是天真的和錯誤的地方。
通過play-slick管理這種依賴關係非常好。我原以爲我會通過在SBT中包含這一行來做到這一點;
"com.typesafe.play" %% "play-slick" % "1.1.0",
但似乎沒有隔離效果,我不確定如何配置它以訪問'官方'漂亮的MS SQL驅動程序。
編輯2 ::最後,這似乎建立我想要的。
name := """hello-slick-3.1"""
lazy val root = (project in file(".")).enablePlugins(PlayScala)
resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/maven-releases/"
resolvers += "Scalaz Bintray Repo" at "https://dl.bintray.com/scalaz/releases"
resolvers += Resolver.url("Typesafe Ivy releases", url("https://repo.typesafe.com/typesafe/ivy-releases"))(Resolver.ivyStylePatterns)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "3.1.0",
"com.typesafe.slick" %% "slick-extensions" % "3.1.0",
"com.typesafe.play" %% "play-slick" % "1.1.0",
"org.scalatest" %% "scalatest" % "2.2.4" % "test"
)
我有很多問題,因爲我忘了包含正確的解析器。
不要忘了,包括正確的解析器:-)。
play-slick只爲您提供開源的Slick。您還需要添加slick-extensions,如手冊中所述。你也有版本衝突。 Slick 3.1中不存在'SimpleQL'。請查看[play-slick](https://github.com/playframework/play-slick/blob/master/README.md)瞭解Play,Play-Slick和Slick的支持版本組合。 – szeiger
我當時很愚蠢......以前我曾嘗試過使用正確的版本,但沒有在哪裏,因爲我沒有添加解析器。如果你讀了這個;試試這個... resolver + =「Typesafe Releases」,位於「http://repo.typesafe.com/typesafe/maven-releases/」 – Simon