造成者:java.sql.SQLException:不支持JDBC4 Connection.isValid()方法 [英] Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not supported

查看:673
本文介绍了造成者:java.sql.SQLException:不支持JDBC4 Connection.isValid()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的play-framework项目在我的本地运行良好,但是当我尝试在heroku中部署它时,出现以下错误。

  2015-07-05T06:24:10.456657 + 00:00应用[web.1]:在com.google.inject .Guice.createInjector(Guice.java:73)
2015-07-05T06:24:10.456817 + 00:00 app [web.1]:在play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder。 scala:93)
2015-07-05T06:24:10.456702 + 00:00 app [web.1]:com.google.inject.Guice.createInjector(Guice.java:62)
2015 -07-05T06:24:10.456746 + 00:00 app [web.1]:在play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126)
2015-07-05T06:24: 10.456863 + 00:00 app [web.1]:在play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
2015-07-05T06:24:10.456909 + 00:00 app [在play.core.server.ProdServerStart $ .start(ProdServerStart.scala:52)
2015-07-05T06:24:10.456951 + 00:00 app [web.1]:在玩。 core.server.ProdServerStart $ .main(ProdServerStart.scala:27)
2015-07-05T06:24:10.456994 + 00:00 app [web.1]:at play.core.server.ProdServerStart.main( ProdSer verStart.scala)
2015-07-05T06:24:10.457407 + 00:00 app [web.1]:at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441)
2015-07-05T06:24:10.457496 + 00:00 app [web.1]:在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)
2015-07-05T06: 24:10.457369 + 00:00 app [web.1]:原因:java.sql.SQLException:不支持JDBC4 Connection.isValid()方法,必须配置连接测试查询
2015-07-05T06:24 :10.457602 + 00:00 app [web.1]:在java.util.concurrent.FutureTask.run(FutureTask.java:266)
2015-07-05T06:24:10.457451 + 00:00 app [web .1]:at com.zaxxer.hikari.pool.BaseHikariPool $ 1.run(BaseHikariPool.java:413)
2015-07-05T06:24:10.457681 + 00:00 app [web.1]:at java .util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2015-07-05T06:24:10.457812 + 00:00 app [web.1]:at java.lang.Thread.run(Thread。 java:745)
2015-07-05T06:24:10.457768 + 00:00 app [web.1]:at java.util.concurrent.Thre adPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)
2015-07-05T06:24:11.231007 + 00:00 heroku [web.1]:进程退出,状态为255
2015-07-05T06 :24:11.243795 + 00:00 heroku [web.1]:状态从开始变为崩溃
2015-07-05T06:24:11.245013 + 00:00 heroku [web.1]:状态从崩溃更改为起始
2015-07-05T06:24:16.259302 + 00:00 heroku [web.1]:用命令`target / universal / stage / bin / sazors -Dhttp.port = 10803`
2015-07-05T06:24:17.542815 + 00:00 app [web.1]:拾取JAVA_TOOL_OPTIONS:-Xmx384m -Xss512k -Dfile.encoding = UTF-8
2015-07-05T06:24:18.643391+ 00:00 app [web.1]:06:24:18,391 | -INFO in ch.qos.logback.classic.LoggerContext [默认] - 找不到资源[logback.groovy]
2015-07-05T06 :24:18.643397 + 00:00 app [web.1]:06:24:18,391 | -INFO in ch.qos.logback.classic.LoggerContext [default] - 找不到资源[logback-test.xml]

我使用PostgreSQL作为我的db和slick作为数据库访问l ibrary。我试图谷歌它和一些研究后,我发现这个错误可能会导致当提供的配置文件中的url不正确或返回null。我试图修复它,但我无法解决这个错误。



这是我的Procfile:


web:target / universal / stage / bin / myapp -Dhttp.port = $ {PORT} -Dconfig.resource = $ {PLAY_CONF_FILE}

和Application.conf

  slick.dbs.default.driver =slick.driver.PostgresDriver $
slick.dbs.default.db.driver =org.postgresql.Driver
slick.dbs.default.db.url =postgres:// rycmvicwkkzofh:Xt2PWggm__FQEHOeq9EoMqTOtF @ ec2-54- 243-132-114.compute-1.amazonaws.com:5432/d5pr4h65obtb0s
slick.dbs.default.db.user = rycmuicwkkzofh
slick.dbs.default.db.password =copiedfromheroku

PS:我正在处理这些修订



play framework version:2.4.0
slick version:3.0



编辑:如果我在application.conf中添加 slick.dbs.default.db.connectionTestQuery =SELECT 1,它会生成新类型的nullPoi nterException错误。

 现在不存在了,但现在又出现新错误:
2015-07-05T12:22:49.781133+ 00:00 app [web.1]:在com.google.inject.Guice.createInjector(Guice.java:73)
2015-07-05T12:22:49.781201 + 00:00 app [web.1] :at com.google.inject.Guice.createInjector(Guice.java:62)
2015-07-05T12:22:49.781283 + 00:00 app [web.1]:at play.api.inject.guice GuiceBuilder.injector(GuiceInjectorBuilder.scala:126)
2015-07-05T12:22:49.781361 + 00:00 app [web.1]:在play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder。 scala:93)
2015-07-05T12:22:49.781507 + 00:00 app [web.1]:在play.core.server.ProdServerStart $ .start(ProdServerStart.scala:52)
2015-07-05T12:22:49.781425 + 00:00 app [web.1]:at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
2015-07-05T12:22 :49.781599 + 00:00 app [web.1]:在play.core.server.ProdServerStart $ .main(ProdServerStart.scala:27)
2015-07-05T12:22:49.781669 + 00:0 0 app [web.1]:在play.core.server.ProdServerStart.main(ProdServerStart.scala)
2015-07-05T12:22:49.782161 + 00:00 app [web.1]:引起: java.lang.NullPointerException
2015-07-05T12:22:49.782226 + 00:00 app [web.1]:at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:446)
2015-07-05T12:22:49.782328 + 00:00 app [web.1]:at com.zaxxer.hikari.pool.BaseHikariPool $ 1.run(BaseHikariPool.java:413)
2015-07- 05T12:22:49.782417 + 00:00 app [web.1]:在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)
2015-07-05T12:22:49.782515 + 00 :00 app [web.1]:at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2015-07-05T12:22:49.783691 + 00:00 app [web.1]:在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2015-07-05T12:22:49.783803 + 00:00 app [web.1]:在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)
2015-07-05T12:22:49.783883 + 00:00 app [web.1]:at java.lang.Thread.run(Thread.java:745)


解决方案

我相信这个问题在 Play邮件列表



事实证明,Slick不支持Heroku设置的DATABASE_URL格式。您将不得不将DATABASE_URL解析为JDBC URL。您可以使用heroku-jdbc库轻松完成此操作:
https://github.com/ jkutner / heroku-jdbc



只需将这样的一行添加到您的代理商:

  libraryDependencies + =com.heroku.sdk%heroku-jdbc%0.1.0

然后你可以像这样解析URL:

  var jdbcURL = DatabaseUrl.extract.jdbcUrl 

然后将该网址传递给slick



实际上,看起来大多数人都是手动解析DATABASE_URL,并且使用硬编码的值设置浮动conf。这很好,但请注意,连接可能会改变,您必须手动更改设置。



因此,您需要将配置更改为此:

  slick.dbs.default.db.url =jdbc:postgresql:// host:port / path

但是,您可能想要销毁并重新创建数据库,因为您已将公开的连接详细信息公开。 / p>

我已经提交了一个PR来修正这个问题:
https://github.com/slick/slick/pull/1193


My play-framework project is running well in my local but when I am trying to deploy it in heroku I am getting following error.

2015-07-05T06:24:10.456657+00:00 app[web.1]:    at com.google.inject.Guice.createInjector(Guice.java:73)
2015-07-05T06:24:10.456817+00:00 app[web.1]:    at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93)
2015-07-05T06:24:10.456702+00:00 app[web.1]:    at com.google.inject.Guice.createInjector(Guice.java:62)
2015-07-05T06:24:10.456746+00:00 app[web.1]:    at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126)
2015-07-05T06:24:10.456863+00:00 app[web.1]:    at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
2015-07-05T06:24:10.456909+00:00 app[web.1]:    at play.core.server.ProdServerStart$.start(ProdServerStart.scala:52)
2015-07-05T06:24:10.456951+00:00 app[web.1]:    at play.core.server.ProdServerStart$.main(ProdServerStart.scala:27)
2015-07-05T06:24:10.456994+00:00 app[web.1]:    at play.core.server.ProdServerStart.main(ProdServerStart.scala)
2015-07-05T06:24:10.457407+00:00 app[web.1]:    at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441)
2015-07-05T06:24:10.457496+00:00 app[web.1]:    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
2015-07-05T06:24:10.457369+00:00 app[web.1]: Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not supported, connection test query must be configured
2015-07-05T06:24:10.457602+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2015-07-05T06:24:10.457451+00:00 app[web.1]:    at com.zaxxer.hikari.pool.BaseHikariPool$1.run(BaseHikariPool.java:413)
2015-07-05T06:24:10.457681+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2015-07-05T06:24:10.457812+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:745)
2015-07-05T06:24:10.457768+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2015-07-05T06:24:11.231007+00:00 heroku[web.1]: Process exited with status 255
2015-07-05T06:24:11.243795+00:00 heroku[web.1]: State changed from starting to crashed
2015-07-05T06:24:11.245013+00:00 heroku[web.1]: State changed from crashed to starting
2015-07-05T06:24:16.259302+00:00 heroku[web.1]: Starting process with command `target/universal/stage/bin/sazors -Dhttp.port=10803`
2015-07-05T06:24:17.542815+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx384m -Xss512k -Dfile.encoding=UTF-8
2015-07-05T06:24:18.643391+00:00 app[web.1]: 06:24:18,391 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
2015-07-05T06:24:18.643397+00:00 app[web.1]: 06:24:18,391 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]

I am using PostgreSQL as my db and slick as database access library. I tried to google it and after some research I found out this error can be caused when provided url in configuration file is incorrect or it is returning null. I tried to fix it but I couldn't resolve this error.

Here is my Procfile:

web: target/universal/stage/bin/myapp -Dhttp.port=${PORT} -Dconfig.resource=${PLAY_CONF_FILE}

and Application.conf

slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="postgres://rycmvicwkkzofh:Xt2PWggm__FQEHOeq9EoMqTOtF@ec2-54-243-132-114.compute-1.amazonaws.com:5432/d5pr4h65obtb0s"
slick.dbs.default.db.user=rycmuicwkkzofh
slick.dbs.default.db.password="copiedfromheroku"

P.S: I am working on these revisions

play framework version : 2.4.0 slick version : 3.0

EDIT: If I add slick.dbs.default.db.connectionTestQuery="SELECT 1" in my application.conf it produces new type of nullPointerException Error.

That is gone but getting new error now:
2015-07-05T12:22:49.781133+00:00 app[web.1]:    at com.google.inject.Guice.createInjector(Guice.java:73)
2015-07-05T12:22:49.781201+00:00 app[web.1]:    at com.google.inject.Guice.createInjector(Guice.java:62)
2015-07-05T12:22:49.781283+00:00 app[web.1]:    at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126)
2015-07-05T12:22:49.781361+00:00 app[web.1]:    at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93)
2015-07-05T12:22:49.781507+00:00 app[web.1]:    at play.core.server.ProdServerStart$.start(ProdServerStart.scala:52)
2015-07-05T12:22:49.781425+00:00 app[web.1]:    at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
2015-07-05T12:22:49.781599+00:00 app[web.1]:    at play.core.server.ProdServerStart$.main(ProdServerStart.scala:27)
2015-07-05T12:22:49.781669+00:00 app[web.1]:    at play.core.server.ProdServerStart.main(ProdServerStart.scala)
2015-07-05T12:22:49.782161+00:00 app[web.1]: Caused by: java.lang.NullPointerException
2015-07-05T12:22:49.782226+00:00 app[web.1]:    at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:446)
2015-07-05T12:22:49.782328+00:00 app[web.1]:    at com.zaxxer.hikari.pool.BaseHikariPool$1.run(BaseHikariPool.java:413)
2015-07-05T12:22:49.782417+00:00 app[web.1]:    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
2015-07-05T12:22:49.782515+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2015-07-05T12:22:49.783691+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2015-07-05T12:22:49.783803+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2015-07-05T12:22:49.783883+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:745)

解决方案

I believe this problem was discussed on the Play mailing list here.

The cause turned out to be that Slick does not support the DATABASE_URL format that Heroku sets. You will have to parse the DATABASE_URL into a JDBC URL. You can do this fairly easily with the heroku-jdbc library: https://github.com/jkutner/heroku-jdbc

Just add a line like this to your deps:

libraryDependencies += "com.heroku.sdk" % "heroku-jdbc" % "0.1.0"

Then you can parse the URL like so:

var jdbcURL = DatabaseUrl.extract.jdbcUrl

Then pass that URL to slick

EDIT

Actually, looks like most people are parsing the DATABASE_URL manually, and setting up slick conf with hard-coded values. This is fine, but be aware that the connection may change, and you'd have to change your settings manually.

So you'll need to change your config to this:

slick.dbs.default.db.url="jdbc:postgresql://host:port/path"

But you might want to destroy and recreate your database because you've posted your connection details in the public.

I've submitted a PR to slick to fix this: https://github.com/slick/slick/pull/1193

这篇关于造成者:java.sql.SQLException:不支持JDBC4 Connection.isValid()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆