公司的公元前代碼底層DB2有這麼一段代碼。java
SQL:web
StringBuffer sql = new StringBuffer("select userdetails.details_date details_date , userdetails.POLICYCODE POLICYCODE, userdetails.ordercode ordercode ,userdetails.plan_name plan_name ,userdetails.integral integral,userdetails.status status , userdetails.details_desc details_desc ,userdetails.person_name USER_NAME from GE_USER_INTEGRALDETAILS userdetails ");
userdetails.person_name 的別名 USER_NAMEspring
ResultSetMetaData md = rs.getMetaData(); int length = md.getColumnCount(); while(rs.next()){ hm = new IndexMap(); for(int i = 0; i < length; i++){ String ColName = md.getColumnName(i+1); hm.put(ColName, rs.getString(ColName)); } result.add(hm); }
這麼一看沒什麼問題,其實裏面埋着巨坑。。。sql
由於業務的發展,要搬到新的數據庫,tomcat/lib 下面有 db2jcc.jar,db2jcc_license_cu.jar,db2jcc4.jar數據庫
(其實包括tomcat7,程序代碼,jar ,JDK6.0 都沒變,只是電腦的內存,硬盤,JJ, 比之前更大了)apache
但新服務器tomcat啓動後,恰恰就是加載了db2jcc4.jar, 而IBM提供的db2jcc4.jar數據庫驅動程序使用了JDBC 4.0,致使結果集映射的規則不一樣於3.0版本,從而致使找不到列的錯誤。tomcat
com.sinosoft.common.DBAccess 2016-12-12 00:02:15,747-- ERROR -- DBAccess執行sql語句時出錯, sql=select userdetails.details_date details_date ,userdetails.POLICYCODE POLICYCODE, userdetails.ordercode ordercode ,userdetails.plan_name plan_name , userdetails.integral integral,userdetails.status status ,userdetails.details_desc details_desc , userdetails.person_name USER_NAME from GE_USER_INTEGRALDETAILS userdetails where userdetails.details_type = ? and userdetails.customerid = ? order by details_date desc fetch first 100 rows only , 參數=com.ibm.db2.jcc.am.SqlException: [jcc][10150][10300][4.17.29] 參數無效:未知列名 PERSON_NAME。 ERRORCODE=-4460, SQL
原來結果集返回了 USER_NAME 的列名,而 md.getColumnName(i+1) 由於是4.0的關係返回的是表的列名而不是結果集的列名,而根據3.0版本,應該返回的是結果集的列名。服務器
至於爲何會加載db2jcc4.jar,也是迷同樣,在本地local跑,根據排序都是先加載db2jcc.jar,而後不加載db2jcc4.jar。session
這裏先記之,只能先解決問題:tomcat/lib 下去掉db2jcc4.jar。app
參考資料:http://ghoulich.xninja.org/2016/01/29/solve-error-code-4460-in-db2/
最後奉上錯誤日誌:
com.sinosoft.common.DBAccess 2016-12-12 00:02:15,745-- ERROR -- listArrEle2Str error java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.String; at com.sinosoft.common.DBAccess.listArrEle2Str(DBAccess.java:559) at com.sinosoft.common.DBAccess.mulparseSQL(DBAccess.java:322) at com.citicpru.integral.service.integralService.impl.IntegralServiceImpl.getMessageByType(IntegralServiceImpl.java:69) at org.apache.jsp.integral.page.getwdtj_jsp._jspService(getwdtj_jsp.java:83) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.citicpru.eservice.filter.XSSFilter.doFilter(XSSFilter.java:73) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.sinosoft.security.Security.doFilter(Security.java:34) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.com.sinosoft.iecs.sso.client.util.AssertionThreadLocalFilter.doFilter(AssertionThreadLocalFilter.java:54) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.com.sinosoft.iecs.sso.client.util.HttpServletRequestWrapperFilter.doFilter(HttpServletRequestWrapperFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.com.sinosoft.iecs.sso.client.authentication.AuthenticationFilter.doFilter(AuthenticationFilter.java:152) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.com.sinosoft.iecs.sso.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:260) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.com.sinosoft.iecs.sso.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.sinosoft.iservice.wechatclaims.filter.WeixinGetOpenidFilter.doFilter(WeixinGetOpenidFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.citicpru.weixin.filter.WeixinOpenidFilter.doFilter(WeixinOpenidFilter.java:191) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.citicpru.eservice.filter.CookieFilter.doFilter(CookieFilter.java:50) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.sinosoft.common.EncodingFilter.doFilter(EncodingFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:662) com.sinosoft.common.DBAccess 2016-12-12 00:02:15,747-- ERROR -- DBAccess執行sql語句時出錯,sql=select userdetails.details_date details_date ,userdetails.POLICYCODE POLICYCODE, userdetails.ordercode ordercode ,userdetails.plan_name plan_name ,userdetails.integral integral,userdetails.status status ,userdetails.details_desc details_desc ,userdetails.person_name USER_NAME from GE_USER_INTEGRALDETAILS userdetails where userdetails.details_type = ? and userdetails.customerid = ? order by details_date desc fetch first 100 rows only ,參數= com.ibm.db2.jcc.am.SqlException: [jcc][10150][10300][4.17.29] 參數無效:未知列名 PERSON_NAME。 ERRORCODE=-4460, SQLSTATE=null at com.ibm.db2.jcc.am.hd.a(hd.java:731) at com.ibm.db2.jcc.am.hd.a(hd.java:66) at com.ibm.db2.jcc.am.hd.a(hd.java:111) at com.ibm.db2.jcc.am.gb.a(gb.java:2132) at com.ibm.db2.jcc.am.ResultSet.findColumnX(ResultSet.java:1932) at com.ibm.db2.jcc.am.ResultSet.getString(ResultSet.java:1704) at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:263) at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:263) at com.sinosoft.common.DBAccess.mulparseSQL(DBAccess.java:314) at com.citicpru.integral.service.integralService.impl.IntegralServiceImpl.getMessageByType(IntegralServiceImpl.java:69) at org.apache.jsp.integral.page.getwdtj_jsp._jspService(getwdtj_jsp.java:83) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.citicpru.eservice.filter.XSSFilter.doFilter(XSSFilter.java:73) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.sinosoft.security.Security.doFilter(Security.java:34) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.com.sinosoft.iecs.sso.client.util.AssertionThreadLocalFilter.doFilter(AssertionThreadLocalFilter.java:54) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.com.sinosoft.iecs.sso.client.util.HttpServletRequestWrapperFilter.doFilter(HttpServletRequestWrapperFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.com.sinosoft.iecs.sso.client.authentication.AuthenticationFilter.doFilter(AuthenticationFilter.java:152) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.com.sinosoft.iecs.sso.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:260) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.com.sinosoft.iecs.sso.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.sinosoft.iservice.wechatclaims.filter.WeixinGetOpenidFilter.doFilter(WeixinGetOpenidFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.citicpru.weixin.filter.WeixinOpenidFilter.doFilter(WeixinOpenidFilter.java:191) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.citicpru.eservice.filter.CookieFilter.doFilter(CookieFilter.java:50) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.sinosoft.common.EncodingFilter.doFilter(EncodingFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:662)