• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sql:query in jsp

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using following syntax .But i am not getting table columns in order as like it is in sql database.

How can i get columns in order like it is in sql database?


<sql:query var="deejays"> SELECT * FROM mytable</sql:query>

<%-- Get the column names for the header of the table --%>
<c:forEach var="columnName" items="${deejays.columnNames}"> <th><c:out value="${columnName}"/></th></c:forEach>

<%-- Get the value of each column while iterating over rows --%>
<c:forEach var="row" items="${deejays.rows}"> <tr> <c:forEach var="column" items="${row}">
<td><c:out value="${column.value}"/></td> </c:forEach> </tr></c:forEach>


Thanks
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bhaskar,
"select *" is risky as you are dependent on an order you don't control. Why not write it more explicitly as "select column1, column2, ... columnN" ?
 
Bacchi Gerem
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried that tooo.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSTL SQL tags were never meant for use in production quality applications.

Here is the top of section 10 in the JSTL spec:


Many web applications need to access relational databases as the source of dynamic
data for their presentation layer. While it is generally preferred to have database
operations handled within the business logic of a web application designed with an
MVC architecture, there are situations where page authors require this capability
within their JSP pages (e.g. prototyping/testing, small scale/simple applications,
lack of developer resources).

The JSTL SQL actions provide the basic capabilities to easily interact with relational
databases.



If you need more specific functionality or if this is part of a real app that will need to be maintained and updated over time, you'll do yourself a favor by dumping the JSTL SQL tags now and move to a proper MVC architecture that allows you to control, exactly, how your data is structured before it ever reaches the JSP.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Additionally, because JSTL SQL tags don't fit in with the whole concept of scriptless JSP, very few experienced developers bother with them. Therefore, as this thread shows, it is hard to get help with them on forums like this.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic