Issue
I am trying to set a DataSource connection; the error I actually get is java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z
but the title's error pops up right above.
--
I have a caffeJdbc.java servlet with this DataSource setting
Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/jdbc/caffeDB");
Connection con = dataSource.getConnection();
--
This is the project web.xml setting, with servlet mapping and resource references
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>tjdbc</servlet-name>
<servlet-class>caffeJdbc</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>tjdbc</servlet-name>
<url-pattern>/caffeJdbc</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>jdbc/caffeDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
--
server.xml
<GlobalNamingResources>
<Resource name="jdbc/caffeDB"
global="jdbc/caffeDB"
url="jdbc:mysql://localhost:3306/caffe"/>
</GlobalNamingResources>
--
And this is the context.xml
<Context path="/JDBCDataSource">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink global="jdbc/caffeDB"
name="jdbc/caffeDB"
type="javax.sql.DataSource">
</ResourceLink>
</Context>
I loaded both JDBC driver and the commons-dbcp2-2.1.1 one in the lib directory and in the path
Solution
May be the JDBC Driver you are using is outdated, Please check that, You can see here for more info.
Answered By - parlad
Answer Checked By - Katrina (JavaFixing Volunteer)