jsp jstl sql与mysql中的奇怪行为 [英] jsp jstl sql strange behaviour with as in mysql
问题描述
在mysql中,我具有一个存储过程,该存储过程具有类似sql的SQL:
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 ;
我正在使用jstl代码获取值:-
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>
但是此代码不会返回任何内容,但是当将上面的代码 $ {rows.i_firstname} 替换为 $ {rows.firstname} 时,我得到了正确的值.
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.
jstl出问题了,这是可复制的还是我的错...
Anything wrong with jstl, is this replicable or my fault here...
谢谢
推荐答案
我知道这是一篇旧文章,但我也遇到了此问题.在这里讨论: http://forums.mysql.com/read.php?39,432843,432862#msg-432862
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
重要的是,mysql论坛中的张贴者指出
Importantly, the poster in the mysql forum states
ResultSetMetaData.getColumnName()将返回列的实际名称,如果存在
这提供了一种解决方法-防止存在列名,因此必须使用别名.例如,原始海报的存储过程可以修改为
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 ;
在这种情况下,原始列现在未知,并且使用别名.我已经在类似的情况下在我的系统上对其进行了测试.同样,如果需要为int使用别名,则可以尝试SELECT(id + 0)AS id_alias.我敢肯定,大多数列类型都有类似的解决方案.希望这会有所帮助.
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.
这篇关于jsp jstl sql与mysql中的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!