問題描述
找到解決方案:我最終將 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 版本錯誤?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!