AbstractMethodError when using isvalid() function with mysql connection object

6.6k Views Asked by At

I am trying overcome mysql connection object timeout problem. I use singleton pattern to get the connection object. My intention is to reinitialize the connection object when mysql connection object timeouts on the server side. Below is my code :

public static Connection getConnection() {
        try {
//            con = dataSource.getConnection();
            if(con==null || !con.isValid(0)){
                logger.info("Creating new connection object...");
                Class.forName(driver);
                con = DriverManager.getConnection(url + "/" + dbName, userName, pass);
                if(con!=null) logger.info("Connection object creation successful!!");
            }else{
                logger.info("Returning existing connection object...");
            }
        } catch (ClassNotFoundException ex) {
            logger.error(ex);
        } catch (SQLException ex) {
            logger.error(ex);
        }
        return con;
    }

Below is the error message I get when attempting to use isValid method :

java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z
    at com.abc.xml2pdf.db.DBUtil.getConnection(DBUtil.java:66)
    at com.abc.xml2pdf.dao.RequestTracking.persistRequest(RequestTracking.java:137)
    at com.abc.xml2pdf.dao.RequestTracking.trackRequest(RequestTracking.java:78)
    at com.abc.xml2pdf.controller.LoginServlet.doGet(LoginServlet.java:61)
    at com.abc.xml2pdf.controller.LoginServlet.doPost(LoginServlet.java:79)

When I dig into the problem , I found that isValid() method is not implemented in com.mysql.jdbc.Connection. Am I missing something. Or will I not be able to use isValid with mysql connector. I am using the latest mysql connector 5.0.8. Kindly clarify. Thanks.

1

There are 1 best solutions below

0
On

The updated Jar from here helped me to solve that without any prob. Thanks all!! :)