jsp jstl sql strange behaviour with as in mysql
In mysql i m having a stored procedure which has a sql like:
select firstname as i_firstname , lastname as i_lastname from roleuser
where user_id = uid ;
I m using a jstl code to get the values: -
<sql:query var="comm_codes" dataSource="jdbc/myDatasource">
call sp_select_username(?);
<sql:param>${user_id}</sql:param>
</sql:query>
<c:forEach var="rows" items="${comm_codes.rows}">
${rows.i_firstname} ${rows.i_lastname}
</c:forEach>
But this code does not return anything but when the replace the above code ${rows.i_firstname} with ${rows.firstname} i get the correct values.
Anything wrong 开发者_StackOverflow中文版with jstl, is this replicable or my fault here...
Question also posted here and here
thanks
I know it is an old post, but I encountered this problem as well. It is discussed here: http://forums.mysql.com/read.php?39,432843,432862#msg-432862
Importantly, the poster in the mysql forum states
ResultSetMetaData.getColumnName() will return the actual name of the column, if it exists
This provides a work-around - prevent the column name from existing, so that the alias must be used. As an example, the original poster's stored procedure could be modified to be
select concat(first name,'') as i_firstname ,
concat(lastname,'') as i_lastname from roleuser
where user_id = uid ;
In this case, the original column is now unknown, and the alias is used. I've tested this on my system in a similar situation at it worked. Likewise, if you need to use an alias for an int, you can try SELECT (id+0) AS id_alias. I'm sure most column types have similar solutions. Hope this helps.
精彩评论