Reputation: 173
I have been bashing my head against a wall all morning trying to figure this one out.
I'm upgrading a very old application and I'm having trouble with the queries in the JSP pages. (I know, I know...)
I have this query within an <sql:query> tag:
SELECT t1.item AS i1, t2.item AS i2 FROM table t1, table t2
In the JSP page, I iterate over the result set and display information. However, i1
and i2
don't exist in the result set, but item
and item
do exist. It appears that the renaming of the column, using the AS
syntax, is failing. Does anyone know why?
I'm using JSTL 1.2. I have both the api
and impl
jars in my library. I'm using a JSP 2.1, Servlet 2.5 servlet container (Tomcat 6, to be exact). I'm using the (as far as I know) correct namespaces for this version of JSTL (<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
,
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
).
The above query functions properly when used in a JSP 2.0, Servlet 2.4 servlet container (Tomcat 5). I'm not sure of the version of JSTL it uses.
The query runs fine when I run it within MySQL Workbench, too.
Upvotes: 1
Views: 1109
Reputation: 173
Per @r0ast3d's suggestion:
"[29 Dec 2007 0:16] Mark Matthews
For many sane reasons, the JDBC experts' group clarified the meaning of "column name" to mean original column name, not the alias (which can be retrieved via the getColumnLabel() method of ResultSetMetaData), therefore our JDBC driver uses this definition when mapping from "name" to column ordinal in ResultSet.get*(String).
You can revert to the old behavior by setting the configuration property "useOldAliasMetadataBehavior" to "true" with our JDBC driver, but applications (and frameworks) really should be changed to support the behavior."
The culprit was the JDBC driver.
Upvotes: 1