Jsp jstl sql weird behavior like in mysql

In mysql, I m have a stored procedure that has sql like:

select firstname as i_firstname , lastname as i_lastname from roleuser where user_id = uid ; 

I am using 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 if I replace the above code $ {rows.i_firstname} with $ {rows.firstname} , I get the correct values.

Something is wrong with jstl, is it replicable or my error is here ...

The question is also posted here and here.

thanks

+4
source share
1 answer

I know this is an old post, but I ran into this problem. Discussed here: http://forums.mysql.com/read.php?39,432843,432862#msg-432862

It is important to note that the poster in the mysql forum states

ResultSetMetaData.getColumnName () will return the actual column name if it exists

This provides a workaround - prevents the use of a column name from an existing one to use an alias. For example, the original planned stored procedure can be modified as

 select concat(first name,'') as i_firstname , concat(lastname,'') as i_lastname from roleuser where user_id = uid ; 

In this case, the source column is now unknown, and an alias is used. I tested this on my system in a similar situation when I worked. Similarly, if you need to use an alias for int, you can try SELECT (id + 0) AS id_alias. I am sure most column types have similar solutions. Hope this helps.

+4
source

Source: https://habr.com/ru/post/1339759/


All Articles