-2

我遇到了麻烦,我不知道为什么我无法连接到数据库,一切都很好。

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[SQLTimeoutException: Timeout after 60001ms of waiting for a connection.]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:293)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:220)
at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160)
at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188)
at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:346)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:345)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)

Caused by: java.sql.SQLTimeoutException: Timeout after 60001ms of waiting for a connection.
at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:227)
at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:182)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:93)
at slick.jdbc.hikaricp.HikariCPJdbcDataSource.createConnection(HikariCPJdbcDataSource.scala:12)
at slick.jdbc.JdbcBackend$BaseSession.conn$lzycompute(JdbcBackend.scala:415)
at slick.jdbc.JdbcBackend$BaseSession.conn(JdbcBackend.scala:414)
at slick.jdbc.JdbcBackend$SessionDef$class.prepareStatement(JdbcBackend.scala:297)
at slick.jdbc.JdbcBackend$BaseSession.prepareStatement(JdbcBackend.scala:407)
at slick.jdbc.StatementInvoker.results(StatementInvoker.scala:33)
at slick.jdbc.StatementInvoker.iteratorTo(StatementInvoker.scala:22)

Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not   supported, connection test query must be configured

at  com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441)
at com.zaxxer.hikari.pool.BaseHikariPool$1.run(BaseHikariPool.java:413)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
... 3 common frames omitted

我的应用程序.conf

slick.dbs.default.db.connectionTimeout=60000
slick.dbs.default.driver="utils.db.TetraoPostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432 /templatesite_db"
slick.dbs.default.db.user="marcus"
slick.dbs.default.db.password="123"
play.http.parser.maxDiskBuffer=100MB
parsers.anyContent.maxLength=100MB

构建.sbt

lazy val root = (project in file("."))
.settings(commonSettings: _*)
.settings(routesGenerator := InjectedRoutesGenerator)
.settings(
    libraryDependencies += "com.typesafe.slick" %% "slick" % "3.1.1",
    libraryDependencies += "com.typesafe.slick" %% "slick-codegen" % "3.1.1",
    libraryDependencies += "com.github.tminglei" %% "slick-pg" % "0.14.1",
    libraryDependencies += "com.github.tminglei" %% "slick-pg_date2" % "0.14.1",
    libraryDependencies += "com.typesafe.play" %% "play-slick" % "2.0.2",
    libraryDependencies += "jp.t2v" %% "play2-auth" % "0.14.2",
    libraryDependencies += play.sbt.Play.autoImport.cache,
    libraryDependencies += "com.github.t3hnar" %% "scala-bcrypt" % "2.6",
    libraryDependencies += "org.webjars" %% "webjars-play" % "2.5.0",
    libraryDependencies += "org.webjars" % "foundation" % "6.2.3"
).enablePlugins(PlayScala)
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
4

1 回答 1

0

我认为这可能是 HikariCP 模块正在寻找一个 connectionTestQuery 而没有找到它(并抛出错误)。尝试将以下内容添加到 application.conf:

slick.dbs.default.db.connectionTestQuery="/*ping*/ select 1" // or whatever

来自:原因:java.sql.SQLException:不支持 JDBC4 Connection.isValid() 方法

于 2017-06-24T17:47:25.840 回答