玩2.5框架和SQL Server 2008 R2连接
Play 2.5 framework and SQL Server 2008 R2 connection
我对 Java 和 Play 2.5 框架非常陌生,但我想通过 VPN 连接到 SQL Server 2008 R2 数据库。
我下载了文件 jtds-1.3.1-dist.zip,我将其解压缩并复制到 libexec 文件夹中。
我在 build.sbt 文件中插入了这一行:
val appDependencies = Seq(
"net.sourceforge.jtds" % "jtds" % "1.3.1"
)
这是 application.conf 文件:
## Database Connection Pool
# https://www.playframework.com/documentation/latest/SettingsJDBC
# ~~~~~
# Play doesn't require a JDBC database to run, but you can easily enable one.
#
# libraryDependencies += jdbc
#
play.db {
# The combination of these two settings results in "db.default" as the
# default JDBC pool:
config = "db"
default = "default"
# Play uses HikariCP as the default connection pool. You can override
# settings by changing the prototype:
prototype {
# Sets a fixed JDBC connection pool size of 50
hikaricp.minimumIdle = 50
hikaricp.maximumPoolSize = 50
}
}
## JDBC Datasource
# https://www.playframework.com/documentation/latest/JavaDatabase
# https://www.playframework.com/documentation/latest/ScalaDatabase
# ~~~~~
# Once JDBC datasource is set up, you can work with several different
# database options:
#
# Slick (Scala preferred option): https://www.playframework.com /documentation/latest/PlaySlick
# JPA (Java preferred option): https://playframework.com/documentation/latest/JavaJPA
# EBean: https://playframework.com/documentation/latest/JavaEbean
# Anorm: https://www.playframework.com/documentation/latest/ScalaAnorm
#
db {
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
# https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
#default.driver = org.h2.Driver
#default.url = "jdbc:h2:mem:play"
#default.username = sa
#default.password = ""
default.url = "jdbc:jtds:sqlserver://xyz.aaa.bbb.global:1433/MyDB;instance=MSSQLSERVER"
default.driver = net.sourceforge.jtds.jdbc.Driver
default.username = username
default.password = "password"
# You can turn on SQL logging for any datasource
# https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
default.logSql=true
}
不幸的是,我总是得到这个错误:
Cannot connect to database [default]
有人能帮帮我吗
最后我用sqljdbc42.jar连接上了。
我没有在 build.sbt 文件中添加任何行,只是将 jar 添加到 lib 文件夹中,并将这两行添加到 application.conf 文件中:
default.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
default.url="jdbc:sqlserver://xxx.yyy.zzz.global:1433;databaseName=MyDB;user=uname;password=pword;"
我对 Java 和 Play 2.5 框架非常陌生,但我想通过 VPN 连接到 SQL Server 2008 R2 数据库。
我下载了文件 jtds-1.3.1-dist.zip,我将其解压缩并复制到 libexec 文件夹中。
我在 build.sbt 文件中插入了这一行:
val appDependencies = Seq(
"net.sourceforge.jtds" % "jtds" % "1.3.1"
)
这是 application.conf 文件:
## Database Connection Pool
# https://www.playframework.com/documentation/latest/SettingsJDBC
# ~~~~~
# Play doesn't require a JDBC database to run, but you can easily enable one.
#
# libraryDependencies += jdbc
#
play.db {
# The combination of these two settings results in "db.default" as the
# default JDBC pool:
config = "db"
default = "default"
# Play uses HikariCP as the default connection pool. You can override
# settings by changing the prototype:
prototype {
# Sets a fixed JDBC connection pool size of 50
hikaricp.minimumIdle = 50
hikaricp.maximumPoolSize = 50
}
}
## JDBC Datasource
# https://www.playframework.com/documentation/latest/JavaDatabase
# https://www.playframework.com/documentation/latest/ScalaDatabase
# ~~~~~
# Once JDBC datasource is set up, you can work with several different
# database options:
#
# Slick (Scala preferred option): https://www.playframework.com /documentation/latest/PlaySlick
# JPA (Java preferred option): https://playframework.com/documentation/latest/JavaJPA
# EBean: https://playframework.com/documentation/latest/JavaEbean
# Anorm: https://www.playframework.com/documentation/latest/ScalaAnorm
#
db {
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
# https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
#default.driver = org.h2.Driver
#default.url = "jdbc:h2:mem:play"
#default.username = sa
#default.password = ""
default.url = "jdbc:jtds:sqlserver://xyz.aaa.bbb.global:1433/MyDB;instance=MSSQLSERVER"
default.driver = net.sourceforge.jtds.jdbc.Driver
default.username = username
default.password = "password"
# You can turn on SQL logging for any datasource
# https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
default.logSql=true
}
不幸的是,我总是得到这个错误:
Cannot connect to database [default]
有人能帮帮我吗
最后我用sqljdbc42.jar连接上了。 我没有在 build.sbt 文件中添加任何行,只是将 jar 添加到 lib 文件夹中,并将这两行添加到 application.conf 文件中:
default.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver default.url="jdbc:sqlserver://xxx.yyy.zzz.global:1433;databaseName=MyDB;user=uname;password=pword;"