Reputation: 1
// this is controller java file..... using Results set object..
@RequestMapping("/viewalluser.htm")
public ModelAndView viewall() throws SQLException
{
ModelAndView mac = new ModelAndView("show");
Connection conn = null;
Statement stet = null;
String query = null;
Connector ct = new Connector();
Conn = ct.get Connection();
stet = Conn.create Statement();
query = "select * from login";
Result Set rs= stet.execute Query(query);
mas.add Object("user", rs);
}
// here will pass the resultset object on jsp page through spring this is show.jsp
<c:if test="${! empty user}">
<c:forEach var="login" items="${user}">
<tr>
<td><c:out value="${login.idp}"></c:out></td>
<td><c:out value="${login.name}"></c:out></td>
<td><c:out value="${login.password}"></c:out> </td>
<td><a href="deletecont.htm?id=${login.id}">delete</a></td>
<td><a href="">Edit</a></td>
</tr>
</c:forEach>
</c:if>
Upvotes: 0
Views: 1938
Reputation: 544
Would be great if you convert you result set inside the controller to the list of simple pojos with getters and setters. Don't forget to release statements, connections.
Upvotes: 0
Reputation: 340723
First, How to convert ResultSet into Object[] and retrieve the data. Secondly, remember about properly closing JDBC connections.
In fact both requiremenents can be achieved using JdbcTemplate
built into Spring. Have a look at methods taking RowMapper
as a parameter - it is much more convenient compared to the solution given in the link above.
Upvotes: 1