在mysql中我有一个存储过程,其中包含一个sql:select firstname as i_firstname , lastname as i_lastname from roleuser where user_id = uid ;我使用jstl代码来获取值: – sql:query var=comm_codes dataSour...

在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.firstname}替换上面的代码${rows.i_firstname}时,我得到了正确的值.
jstl有什么问题,这是可复制的还是我的错…
问题还发布在here和here
谢谢
解决方法:
我知道这是一个老帖子,但我也遇到了这个问题.这里讨论:http://forums.mysql.com/read.php?39,432843,432862#msg-432862
重要的是,mysql论坛中的海报说明
ResultSetMetaData.getColumnName() will return the actual name of the column, if it exists
这提供了一种解决方法 – 防止列名存在,因此必须使用别名.例如,原始海报的存储过程可以修改为
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.我敢肯定大多数列类型都有类似的解决方案.希望这可以帮助.
本文标题为:java – jsp jstl sql与mysql中的奇怪行为


基础教程推荐
- 关于后缀表达式的java实现过程 2023-02-28
- JAVA的DES加密解密在windows上测试一切正常,在linux上异常 2023-09-01
- java日期时间格式化@JsonFormat与@DateTimeFormat的使用 2023-04-17
- Java设计模式之外观模式 2023-06-05
- JSP 获取用户的真实IP两种实现方法详解 2023-08-01
- 一文带你了解Java中的Object类及类中方法 2023-04-17
- Java web实现头像上传以及读取显示 2023-01-29
- idea web项目没有小蓝点的的两种解决方法 2023-02-27
- Spring3.0配置多个事务管理器的方法 2023-07-31
- Springboot详解线程池与多线程及阻塞队列的应用详解 2023-01-13