AbstractMethodError with jTDS JDBC Driver on Tomcat 8
The answer mentioned above by Marcus worked for me when I encountered this problem. To give a specific example of how the validationQuery setting looks in the context.xml file:
<Resource name="jdbc/myDB" auth="Container" type="javax.sql.DataSource"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://SQLSERVER01:1433/mydbname;instance=MYDBINSTANCE"
username="dbuserid" password="dbpassword"
validationQuery="select 1"
/>
The validationQuery setting goes in with each driver setting for your db connections. So each time you add another db entry to your context.xml file, you will need to include this setting with the driver settings.
Turns out I had to add:
validationQuery="select 1"
in the Resource declaration in context.xml
.
This is mentioned here (although mispelled as validateQuery
).
Digging into the implementation of JtdsConnection
one sees:
/* (non-Javadoc)
* @see java.sql.Connection#isValid(int)
*/
public boolean isValid(int timeout) throws SQLException {
// TODO Auto-generated method stub
throw new AbstractMethodError();
}
This is really weird, I think AbstractMethodError is supposedly thrown by the compiler only, unimplemented methods ought to throw UnsupportedOperationException. At any rate, the following code from PoolableConnection shows why the presence or not of validationQuery
in context.xml
can change things. Your validationQuery
is passed as the value of the sql
String
parameter in the below method (or null
if you don't define a validationQuery
):
public void More ...validate(String sql, int timeout) throws SQLException {
...
if (sql == null || sql.length() == 0) {
...
if (!isValid(timeout)) {
throw new SQLException("isValid() returned false");
}
return;
}
...
}
So basically if no validationQuery
is present, then the connection's own implementation of isValid
is consulted which in the case of JtdsConnection
weirdly throws AbstractMethodError
.