Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Book {
- private int idbook;
- private String name;
- private int type_idtype;
- public int getIdbook() {
- return idbook;
- }
- public void setIdbook(int idbook) {
- this.idbook = idbook;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getType_idtype() {
- return type_idtype;
- }
- public void setType_idtype(int type_idtype) {
- this.type_idtype = type_idtype;
- }
- }
- public class Type {
- private int idtype;
- private String typename;
- public int getIdtype() {
- return idtype;
- }
- public void setIdtype(int idtype) {
- this.idtype = idtype;
- }
- public String getTypename() {
- return typename;
- }
- public void setTypename(String typename) {
- this.typename = typename;
- }
- }
- Statement stmt;
- stmt = conn.createStatement();
- String sql = "SELECT book.name, type.typename from book Join type
- on type.idtype=book.type_idtype";
- ResultSet rs = stmt.executeQuery(sql);
- Book b;
- Type t;
- List<Book> list = new ArrayList<Book>();
- while(rs.next())
- {
- int count = rs.getRow();
- b= new Book();
- t=new Type();
- b.setName(rs.getString("name"));
- t.setTypename(rs.getString("typename"));
- list.add(b);
- }
- request.getSession().setAttribute("list", list);
- response.sendRedirect("booksjsp.jsp");
- stmt.close();
- conn.close();
- <% List list = (List)session.getAttribute("list"); %>
- <table border="1">
- <tr>
- <th>Name</th>
- <th>Name</th>
- </tr>
- <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
- <c:forEach items="${list}" var="element">
- <tr>
- <td>${element.name}</td>
- <td>${element.typename}</td>
- </tr>
- </c:forEach>
- </table>
Add Comment
Please, Sign In to add comment