获取方法 org.postgresql.jdbc4.Jdbc4Connection.isValid(int) 尚未实现

Getting Method org.postgresql.jdbc4.Jdbc4Connection.isValid(int) is not yet implemented

我创建了一个新的 Play 2.5.3 项目,但遇到了这个错误。

我在另一个答案中看到驱动程序已过时,所以我添加了我认为是最新的驱动程序,如下所示:

我像这样添加了 postgress 驱动程序依赖项:

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs,
  "postgresql" % "postgresql" % "9.1-901-1.jdbc4"
)

但仍然出现错误。知道如何解决这个问题吗?

看来9.1-901版本的驱动真的没有实现这个功能
看一段源码: http://grepcode.com/file/repo1.maven.org/maven2/postgresql/postgresql/9.1-901.jdbc4/org/postgresql/jdbc4/AbstractJdbc4Connection.java#AbstractJdbc4Connection.isValid%28int%29

117    public boolean isValid(int timeout) throws SQLException
118    {
119        checkClosed();
120        throw org.postgresql.Driver.notImplemented(this.getClass(), "isValid(int)");
121    }

您可以使用更新版本的驱动,目前最新的驱动是:版本9.4-1208,看这个link:https://jdbc.postgresql.org/


或者您可以自己实现此功能 - 您可以从此处复制它们的实现:
http://grepcode.com/file/repo1.maven.org/maven2/org.postgresql/postgresql/9.4-1201-jdbc41/org/postgresql/jdbc4/AbstractJdbc4Connection.java#AbstractJdbc4Connection.isValid%28int%29

127    public boolean isValid(int timeout) throws SQLException
128    {
129        if (isClosed()) {
130            return false;
131        }
132     if (timeout < 0) {
133            throw new PSQLException(GT.tr("Invalid timeout ({0}<0).", timeout), PSQLState.INVALID_PARAMETER_VALUE);
134        }
135     boolean valid = false;
136        Statement stmt = null;
137     try {
138         if (!isClosed()) {
139             stmt = createStatement();
140             stmt.setQueryTimeout( timeout );
141             stmt.executeUpdate( "" );
142             valid = true;
143         }
144     }
145     catch ( SQLException e) {
146         getLogger().log(GT.tr("Validating connection."),e);
147     }
148     finally
149     {
150         if(stmt!=null) try {stmt.close();}catch(Exception ex){}
151     }
152        return valid;    
153}