jsp jstl sql 与 mysql 中的 as 的奇怪行为
在mysql中,我有一个存储过程,其中有一个sql,例如:
select firstname as i_firstname , lastname as i_lastname from roleuser
where user_id = uid ;
我使用jstl代码来获取值:-
<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} 我得到了正确的值。
jstl 有什么问题吗,这是可复制的还是我的错...
谢谢
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 with jstl, is this replicable or my fault here...
Question also posted here and here
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道这是一个旧帖子,但我也遇到了这个问题。这里讨论: http://forums.mysql.com/ read.php?39,432843,432862#msg-432862
重要的是,mysql 论坛中的海报指出
这提供了一种解决方法 - 防止列名称存在,因此必须使用别名。例如,原始发布者的存储过程可以修改为:
在这种情况下,原始列现在未知,并且使用别名。我已经在我的系统上在类似的情况下测试了它的工作原理。同样,如果需要为 int 使用别名,可以尝试 SELECT (id+0) AS id_alias。我确信大多数列类型都有类似的解决方案。希望这有帮助。
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
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
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.