I'm trying write a test for a method that returns a java.sql.Connection to connect to a PostgreSQL.
My test is very straightforward:
@Test
public void connectionFactoryShouldReturnOpenConnection() throws Exception {
Connection conn = ConnectionFactory.getConnection();
assertTrue(conn.isValid(2));
}
The isValid
call fails, though:
org.postgresql.util.PSQLException: Method org.postgresql.jdbc4.Jdbc4Connection.isValid(int) is not yet implemented.
at org.postgresql.Driver.notImplemented(Driver.java:753)
at org.postgresql.jdbc4.AbstractJdbc4Connection.isValid(AbstractJdbc4Connection.java:109)
at org.postgresql.jdbc4.Jdbc4Connection.isValid(Jdbc4Connection.java:21)
What's going on? Surely there is a PostgreSQL JDBC driver that implements the methods of Java 1.6 such as isValid()
?
Here the details on the driver I'm using:
<groupId&g开发者_开发问答t;postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.0-801.jdbc4</version>
Perform a simple query, if it works, it's valid. If not, it's not.
And by simple query I mean something like:
SELECT 1;
Really simple.
From the postresql driver source code the AbstractJdbc4Connection.isValid()
throws this exception when called:
public boolean isValid(int timeout) throws SQLException
{
checkClosed();
throw org.postgresql.Driver.notImplemented(this.getClass(), "isValid(int)");
}
精彩评论