我试图在我的application.conf
中使用Play Framework的MSSQL服务器 db.url=jdbc:microsoft:sqlserver://localhost\SQL2008:1433;DatabaseName=testDB
db.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
db.user=sa
db.pass=sa
得到以下错误
Database error
A database error occured : Cannot connected to the database, [Microsoft][SQLServer
2000 Driver for JDBC]Error establishing socket.
play.exceptions.DatabaseException: Cannot connected to the database, [Microsoft]
[SQLServer 2000 Driver for JDBC]Error establishing socket.
at play.db.DBPlugin.onApplicationStart(DBPlugin.java:132)
at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:425)
at play.Play.start(Play.java:495)
at play.Play.detectChanges(Play.java:599)
at play.Invoker$Invocation.init(Invoker.java:186)
at Invocation.HTTP Request(Play!)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error
establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
我已将sqljdbc4.jar添加到lib文件夹中。 甚至尝试过使用mssqlserver.jar,msutil.jar,msbase.jar
答案 0 :(得分:6)
对于某些人来说可能很有用,他们一直在寻找MSSQL。
首先下载jtds
将jtds jar文件复制到
play-1.2.3\framework\lib
以及您的应用程序lib文件夹
重新开始播放
在你的application.conf
中 # If you need a full JDBC configuration use the following :
db.url=jdbc:jtds:sqlserver://localhost:1433/testDB;instance=SQL2008
db.driver=net.sourceforge.jtds.jdbc.Driver
db.user=sa
db.pass=sa
开始播放:)
Play2更新
向您的Build.scala
添加播放依赖项
val appDependencies = Seq(
"net.sourceforge.jtds" % "jtds" % "1.2"
)
Play2中的conf
文件发生了变化......
db.default.url="jdbc:jtds:sqlserver://localhost:1433/testDB;instance=SQL2008"
db.default.driver=net.sourceforge.jtds.jdbc.Driver
db.default.user=sa
db.default.pass=sa
restart play SBT
将为您下载依赖项。开始玩:)
答案 1 :(得分:0)
看起来无法连接到在localhost:1433端口上运行的ms sql server。您可能会检查以下几点:
您是否在localhost上运行了ms sql server?
您的ms sql服务器上是否启用了TCP / IP?
你有ms sql server收听1433端口吗?
答案 2 :(得分:0)
尝试从您的网址中删除SQL2008部分
db.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDB
答案 3 :(得分:0)
对于play framework 2.5以下是我的配置
db.default.driver=net.sourceforge.jtds.jdbc.Driver
db.default.url="jdbc:jtds:sqlserver://ipaddress:1433/TESTDB"
db.default.username=USER
db.default.password="Password"
db.default.hikaricp.connectionTestQuery="SELECT 1"
并添加了一个依赖
val appDependencies = Seq(
"net.sourceforge.jtds" % "jtds" % "1.2"
)
此外,如果你使用的是Ebean,那么在plugin.sbt中添加ebean pluging为
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
最后在conf as
ebean.default = ["models.*"]