开发环境参考:
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 Workbench 版本中使用 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);
}
此外,我在 Google 搜索中发现 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.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(Native Method) 在 sun.reflect.NativeMethodinvAccessorImpl.Nmpl. .java:57) 在 sun.reflect。