这就是我所做的。我想得到每个下面的股票,股票名称和股票价格。但不幸的是,它一直在循环。我的意思是,它假设只有S0001 XXX 19.90,而是它有S0001 ABC 19.90,S0002 ABC 19.90,S0003 ABC 19.90,S0004 ABC 19.90。然后它将返回到S0001,ABC将更改为我的数据库中的下一个值。这意味着我的stockname循环4次,而我的股票价格循环12次。
<sql:setDataSource url="jdbc:derby://localhost:1527/healthdb;user=nbuser;password=nbuser" driver="org.apache.derby.jdbc.ClientDriver"
var="Derbydata"/>
<sql:query sql=" SELECT stockid FROM STOCKS" dataSource="${Derbydata}" var="STOCKS" />
<sql:query sql=" SELECT stockname FROM STOCKS" dataSource="${Derbydata}" var="STOCKS1" />
<sql:query sql=" SELECT stockprice FROM STOCKS" dataSource="${Derbydata}" var="STOCKS2" />
<table border="1">
<thead>
<tr><th>
Stock ID
</th>
<th>
Stock Name
</th>
<th>
Stock Price
</th>
</tr>
</thead>
<tbody>
<c:forEach var="row3" items ="${STOCKS2.rowsByIndex}">
<c:forEach var="row2" items ="${STOCKS1.rowsByIndex}">
<c:forEach var="row1" items="${STOCKS.rowsByIndex}">
<tr>
<td>
<c:out value="${row1[0]}"/>
</td>
<td>
<c:out value="${row2[0]}"/>
</td>
<td>
<c:out value="${row3[0]}"/>
</td>
</tr>
答案 0 :(得分:0)
只需将查询更改为所需字段并使用索引或0 1 2 ....
<sql:query sql=" SELECT stockid,stockname,stockprice FROM STOCKS" dataSource="${Derbydata}" var="STOCKS" />
<c:forEach var="row1" items="${STOCKS.rowsByIndex}">
<tr>
<td>
<c:out value="${row1[0]}"/>
</td>
<td> <c:out value="${row1[1]}"/></td>
<td> <c:out value="${row1[2]}"/></td>
</tr>