开发环境参考:
Fedora FC18
Tomcat Server 7.0.39 (localhost config)
Eclipse Juno Release 2
Mysql-connecor-java Ver. 5.1.26 (jar)
Mysql-server Ver. 5.5.32 (jar)
下面的SELECT语句失败,“列‘深度’未找到”:
"select node.subEntityID, node.lft, node.rgt, (count(parent.subEntityID) - 1) as depth
from ENTITY as node, ENTITY as parent
where node.lft between parent.lft and parent.rgt
group by node.subEntityID order by node.lft";
这个SELECT语句成功使用命令级别的MySQL作为
use dbName;
select node.subEntityID, node.lft, node.rgt, (count(parent.subEntityID) - 1) as depth
from ENTITY as node, ENTITY as parent
where node.lft between parent.lft and parent.rgt
group by node.subEntityID order by node.lft;
使用MySQL工作台的SQL查询时版本的select语句也成功。 5.2.4.7。
相关的Java代码片段下面给出:
rs = stmt.executeQuery(typeEntityList);
// The depth alias does not print out in this for loop
for (int i=1; i<rs.getMetaData().getColumnCount()+1; i++) {
System.out.println(rs.getMetaData().getColumnName(i));
System.out.println(rs.getMetaData().getColumnLabel(i));
}
while (rs.next()) {
// "depth" fails at the following statement
System.out.println("depth: " + rs.getInt("depth"));
String s = rs.getString("lft") + " "
+ rs.getString("subEntityID") + " "
+ rs.getString("rgt");
System.out.println(s);
entityList.add(s);
}
另外,我在谷歌搜索的是MySQL的别名行为在最新版本的改变中。 一个建议的修复是追加"?useOldAliasMetadataBehavior=true"
到MySQL连接字符串恢复到原来的行为,但这并没有解决这个问题。
这里的堆栈跟踪:
值java.sql.SQLException:列“深度”没有找到。 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975 )在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)在com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1167)在com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java: 5733)在EntityAssessmentEntityActions.EntityAssessmentEntityListAction.detailedEntityList(EntityAssessmentEntityListAction.java:184)在EntityAssessmentEntityActions.EntityAssessmentEntityListAction.execute(EntityAssessmentEntityListAction.java:69)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl的.java:57)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在java.lang.reflect.Method.invoke(Method.java:606)在com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActi onInvocation.java:450)在com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252)在org.apache.struts2.interceptor.debugging .DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)在融为一体。 opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java: 265)在org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)在com.opensymphony.xwork2.interceptor。 MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)在com.opensymphony .xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)在com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98 )在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)在com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept( MethodFilterInterceptor.java:98)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.int erceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)在COM .opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246 )在org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept( ModelDrivenInterceptor.java:100)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.interceptor.ScopedModelDrivenInte rceptor.intercept(ScopedModelDrivenInterceptor.java:141)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)在com.opensymphony .xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)在com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98 )在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation。的java:246)在org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvoc ation.java:246)在com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在com.opensymphony.xwork2.interceptor .ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)在com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)在org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)在有机apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:546)在org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)在org.apache.struts2.dispatcher.ng.filter。 StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)在组织.apache.catalina。 core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)在org.apache.catalina.valves.AccessLogValve.invoke (AccessLogValve.java:947)在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)在org.apache。 coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)在org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:589)在org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run( JIoEndpoint.java:312)在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:11 45)在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)在java.lang.Thread.run(Thread.java:724)