I'm pretty new with JSP. I am trying to select 2 sql statements to produce 2 separate tables. I could successfully select 1 table,but when i tried 2 tables i can't get it to run. What I did was.
setting up my connection:
<%
String driverName = "com.mysql.jdbc.Driver";
String connectionUrl = "jdbc:mysql://localhost:3306/";
String dbName = "supr";
String userId = "root";
String password = "secret";
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
ResultSet resultSet2 = null;
%>
Connect and execute Query
<%
try {
connection = DriverManager.getConnection(
connectionUrl + dbName, userId, password);
statement = connection.createStatement();
String sql = "SELECT con.container_id, con.con_location, con.con_status, concap.capacity FROM container con INNER JOIN con_capacity concap ON con.container_id = concap.container_id";
String sql2 = "SELECT p.pipe_id, p.pipe_location, pd.PipeDis_date FROM pipe p JOIN pipe_disinfect pd ON p.pipe_id = pd.pipe_id ";
resultSet = statement.executeQuery(sql);
resultSet2 = statement.executeQuery(sql2);
%>
This first table works well alone.
<table class="table table-hover">
<thead>
<th>Container ID</th>
<th>Location</th>
<th>Status</th>
<th>Capacity</th>
<th></th>
</thead>
<tbody>
<%
while (resultSet.next()) { %>
<tr>
<td><%=resultSet.getString("Container_ID")%></td>
<td><%=resultSet.getString("Con_Location")%></td>
<td><%=resultSet.getString("Con_Status")%></td>
<td><%=resultSet.getString("Capacity")%></td>
<td><button class="btn btn-primary">Schedule</button></td>
</tr>
</tbody>
<%
}
} catch (Exception e) {
e.printStackTrace();
}
%>
</table>
But when I tried combining with a second table as below, then I cant get it to run.
<table class="table table-hover">
<thead>
<th>Pipe ID</th>
<th>Location</th>
<th>Last Disinfection</th>
<th></th>
</thead>
<tbody>
<%
while (resultSet2.next()) { %>
<tr>
<td><%=resultSet2.getString("Pipe_ID")%></td>
<td><%=resultSet2.getString("Pipe_Location")%></td>
<td><%=resultSet2.getString("Pipe_LastDisinfect")%></td>
<td><button class="btn btn-primary">Schedule</button></td>
</tr>
</tbody>
<% /**I'm getting an error on this line on eclipse****/
}
} catch (Exception e) {
e.printStackTrace();
}
%>
</table>
and I got internal server error from GlassFish