com.mysql.jdbc.connection.isvalid,java.lang.AbstractMethodError:com.mysql.jdbc.Connection.isValid(I)...

I am trying to connect my Servlet to mysql database using data Source . But whenever I run my servlet I end up getting this exception :

java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z

org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.isValid(DelegatingConnection.java:913)

org.apache.tomcat.dbcp.dbcp2.PoolableConnection.validate(PoolableConnection.java:282)

org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:356)

org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2306)

org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2289)

org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2038)

org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1532)

Servlet.AbdulTayyebs.processRequest(AbdulTayyebs.java:36)

Servlet.AbdulTayyebs.doGet(AbdulTayyebs.java:57)

javax.servlet.http.HttpServlet.service(HttpServlet.java:622)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Here is my Content.xml

type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"

url="jdbc:mysql://127.0.0.1:4000/abdultayyebs?zeroDateTimeBehavior=convertToNull"

username="root" password="february1996" maxActive="5" maxIdle="2"

maxWait="1000"/>

Here is my web.xml

DB Connection

jdbc/abdultayyebs

javax.sql.DataSource

Container

And here is my servlet AbdulTayyebs

import java.io.IOException;

import java.io.PrintWriter;

import java.sql.Connection;

import java.sql.SQLException;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.sql.DataSource;

public class AbdulTayyebs extends HttpServlet {

DataSource ds=null;

@Override

public void init(ServletConfig config)throws ServletException{

try {

Context initContext = new InitialContext();

Context envContext = (Context)initContext.lookup("java:/comp/env");

ds = (DataSource)envContext.lookup("jdbc/abdultayyebs");

} catch (Exception e) {

throw new ServletException("Something went wrong while Initializing the Servlet",e);

}

}

protected void processRequest(HttpServletRequest request,

HttpServletResponse response)

throws ServletException,IOException {

PrintWriter write = response.getWriter();

try {

Others.Action a = Others.ActionFactory.CreateAction(request);

try(Connection c=ds.getConnection()){

String page = a.Execute(c,request,request.getSession(false));

request.getRequestDispatcher(page).forward(request, response);

}

}

catch (SQLException e) {

write.println(e);

}

catch (ServletException e) {

write.println(e);

}

catch (Exception e) {

write.println(e);

}

}

@Override

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

processRequest(request, response);

}

}

I also added the mysql jdbc driver in the lib folder of tomcat but even this didnt helped ? It would be highly appreciable if anybody can help me out

解决方案java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z

This means that the MySQL JDBC driver is outdated as such that it doesn't support Java 1.6's Connection#isValid() method.

Upgrade it. And make sure that you've only one MySQL JDBC driver JAR file in the runtime classpath.

See also:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值