2016-05-31 42 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} 
相關問題