I am trying to connect to a database, execute a select statement, and then output the results of that statement in a JSP page. I have been able to connect to the DB, and (I think) execute the command, but either my ResultSet
has nothing in it, or I am not displaying the results properly.
I have looked at some examples of how this is done, and my code is pretty much identical. When I run the code the resulting web page only has these empty lines where the output data should be. It does however, have three rows of empty lines, which is the number of tuples the query should return. My code is:
String query = "SELECT L.O_ID, L.INV_ID, L.OL_QUANTITY, L.OL_PRICE "
+ "FROM ORDERS O, ORDER_LINE L, ORDERSOURCE S "
+ "WHERE S.OS_DESC = 'Web Site' "
+ "AND O.OS_ID = S.OS_ID "
+ "AND L.O_ID = O.O_ID";
System.out.println(query);
ResultSet results = statement.executeQuery(query);
%>
<table border="1" width="50%" cellspacing="1" cellpadding="0" bordercolor="black" border="1">
<tr>
<th><font size="2"/>Order ID</th>
<th><font size="2"/>Inventory ID</th>
<th><font size="2"/>Quantity</th>
<th><font size="2"/>Price</th>
</tr>
<%while(results.next()) { %>
<tr>
<td><% results.getString("O_ID"); %></td>
<td><% results.getString("INV_ID"); %></td>
<td><% results.getString("OL_QUANTITY"); %></td>
<td><% results.getString("OL_PRICE"); %></td>
</tr>
<% } %>
</table>
</body>
</html>
Also, when I tried to run the query with a ;
at the end, it would not run. But when I removed it it ran. Is there some reason you don't need to terminate queries with a ;
when using JDBC?