2016-05-31 79 views
0

我创建了一个新的Play 2.5.3项目,并且出现此错误。获取方法org.postgresql.jdbc4.Jdbc4Connection.isValid(int)尚未实现

我在另一个阅读回答司机是过时的,所以我说什么,我相信是这样的最新驱动程序:

我说这样的postgress驱动程序相关:

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

但仍然收到错误。任何想法如何解决这个问题?

+1

最新版本是'“org.postgresql”%“PostgreSQL的”%“1208年9月4日”' 。 – marcospereira

回答

2

看来,这个功能真的没有司机
看到源代码的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,请参阅此链接:https://jdbc.postgresql.org/


或者你可以自己实现这个funcion - 你可以从这里复制及其履行情况:
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} 
相关问题