问题描述
找到解决方案:我最终将 db2jcc4.jar 放在 Tomcat 8 的 Tomcat lib 文件夹中,我们可以开始了.但是同样不适用于 Tomcat7,所以我将 db2jcc.jar 从项目外部 jar 引用中取出,让服务器确定要使用哪个版本
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
原始问题
谷歌搜索已经为这个问题产生了一系列神秘的参考:哪个版本的 db2jcc 与 jre 1.7 一起使用.
Googling has produced a slew of cryptic references for this question: which version of db2jcc to use with jre 1.7.
此页面列出了驱动程序下载按db2版本,但不是 JRE.
This page lists the driver downloads by db2 version, but not JRE.
让我知道这个谜团的问题是我们有两台 Tomcat 服务器,一台运行 JRE 1.8,一台运行 1.7.奇怪的是,前者运行的是 Tomcat 7,后者运行的是 Tomcat 8.(你可以问,但我没有答案)
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)
所以我们的开发代码运行良好,可以从我们的 Tomcat 7 JRE 1.8 系统连接到 db2,但是部署到我们的 Tomcat 8 JRE 1.7 服务器的其他东西可能会因为那里更新到 JRE 1.8 而损坏,所以我们怀疑有错误,如图所示下面,是 JRE 1.7 和我们的 db2jcc.jar 文件之间的版本不匹配.
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.
不过,这可能是 Tomcat 8 的问题.
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
最后,我在 Tomcat 7 JRE 1.8 上开发和测试的项目是在 Eclipse 中构建的,符合 JRE 1.7.那么为什么我们会得到这个错误呢?似乎是版本兼容性问题?
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?
注意:我们使用的是在 context.iml 文件中配置的池连接资源,如下所示:
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"
/>
推荐答案
这个问题已经在上面的评论和更新中回答了.
This question has been answered in the comments and update above.
特别是:将已知可与给定 Tomcat 版本一起使用的 jar 文件放在服务器上的 lib 文件夹中,并将其从应用程序中删除,允许服务器而不是应用程序来处理连接,尤其是当我们使用连接池时.
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.
因此我们可以将 db2jcc.jar 放在 tomcat 7 上,将 db2jcc4.jar 放在 tomcat 8 上,并且在部署到任一服务器时应用程序代码不需要更改.
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.
这篇关于与 JRE 1.7 一起使用的 db2jcc.jar 版本错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!