Bad version of db2jcc.jar used with JRE 1.7?

2019-08-08 11:24发布

Solution Found: I wound up putting db2jcc4.jar on Tomcat 8 in the Tomcat lib folder and we're good to go. Same doesn't work for Tomcat7 however, so I took the db2jcc.jar out of the project external jar references and let the server determine which version to use instead

Original Question

Googling has produced a slew of cryptic references for this question: which version of db2jcc to use with jre 1.7.

This page lists the driver downloads by db2 version, but not JRE.

The problem that led me to this mystery is we have two Tomcat servers, one running JRE 1.8 and one running 1.7. Oddly enough, the former is running Tomcat 7 and the later Tomcat 8. (you can ask but I don't have an answer for this)

So our development code is running fine making connections to db2 from our Tomcat 7 JRE 1.8 system, but other things deployed to our Tomcat 8 JRE 1.7 server are feared breakable by updating to JRE 1.8 there, so we suspect an error, shown below, to be a version mismatch between JRE 1.7 and our db2jcc.jar file.

Perhaps it is a problem with Tomcat 8, though.

The error, extracted from the stack trace:

java.lang.AbstractMethodError: com.ibm.db2.jcc.t4.b.isValid(I)Z

Now a final wrinkle, the project that I have developed and tested on Tomcat 7 JRE 1.8 is built in Eclipse with JRE 1.7 compliance. So why would we get this error? Does it appear to be a version compatibility issue?

More complete (but not full) stack trace

    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
 root cause javax.servlet.ServletException: java.lang.AbstractMethodError: com.ibm.db2.jcc.t4.b.isValid(I)Z
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:908)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:837)
    org.apache.jsp.getTimesheetsForUser_jsp._jspService(getTimesheetsForUser_jsp.java:112)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    root cause java.lang.AbstractMethodError: com.ibm.db2.jcc.t4.b.isValid(I)Z
    org.apache.tomcat.dbcp.dbcp2.DelegatingConnection.isValid(DelegatingConnection.java:913)
    org.apache.tomcat.dbcp.dbcp2.PoolableConnection.validate(PoolableConnection.java:226)
    org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:302)
    org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2208)
    org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2191)
    org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1945)
    org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1412)
    com.hr.timesheets.JDBCConnection.queryProdData(JDBCConnection.java:226)
    com.hr.timesheets.TimeSheetQueryManager.getTimesheets(TimeSheetQueryManager.java:624)
    com.hr.timesheets.TimeSheetQueryManager.generateUploadsForUser(TimeSheetQueryManager.java:343)
    org.apache.jsp.getTimesheetsForUser_jsp._jspService(getTimesheetsForUser_jsp.java:94)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Can anyone see something obvious here that our team is missing? Anyone else have this problem before?

Note: we are using pooled connection resources configured in our context.iml file, as shown here:

<Resource auth="Container" 
name="jdbc/hrdb2"
type="javax.sql.DataSource" 
driverClassName="com.ibm.db2.jcc.DB2Driver"
url="jdbc:db2://hrdb2.hr.com:50200/time"
username="redacted" 
password="redacted"
maxIdle="10"
maxActive="400"
maxWait="5"
removeAbandoned="true"
removeAbandonedTimeout="1200"
/> 

标签: java tomcat db2
1条回答
不美不萌又怎样
2楼-- · 2019-08-08 12:12

This question has been answered in the comments and update above.

Specifically: putting the jar file known to work with a given Tomcat release in the lib folder on the server, and removing it from the application, allows the server to handle the connectivity instead of the application, especially as we use connection pooling.

So we can put db2jcc.jar on tomcat 7 and db2jcc4.jar on tomcat 8 and the application code need not change when deploying to either server.

查看更多
登录 后发表回答