jsp jstl sql 与 mysql 中的 as 的奇怪行为

发布于 2024-10-17 13:01:25 字数 897 浏览 3 评论 0原文

在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 有什么问题吗,这是可复制的还是我的错...

问题也发布了 此处此处< /a>

谢谢

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁的年少不轻狂 2024-10-24 13:01:25

我知道这是一个旧帖子,但我也遇到了这个问题。这里讨论: http://forums.mysql.com/ read.php?39,432843,432862#msg-432862

重要的是,mysql 论坛中的海报指出

ResultSetMetaData.getColumnName() 将返回列的实际名称,如果存在

这提供了一种解决方法 - 防止列名称存在,因此必须使用别名。例如,原始发布者的存储过程可以修改为:

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。我确信大多数列类型都有类似的解决方案。希望这有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文