0

I am developing a blog in java struts I want when to open a post(All record are displayed by the database ) than how to make a link see the next post and the previous post.

public static PostInfo getPrevId(String postUrl) {
    PostInfo post = null;
    try {
        Connection conn = ConnectionManager.getConnection();
        PreparedStatement ps = conn.prepareStatement("SELECT posturl FROM blogpost WHERE posturl = ?");
        ps.setString(1, postUrl);
        ResultSet rs = ps.executeQuery();
        rs.afterLast();
        rs.previous();
        post = new PostInfo(rs.getString("posturl"));

    } catch (Exception e) {
        e.printStackTrace();
    }

    return post;
}

Please help me to make the link.

1 Answers1

0

Pass id of previous and next blog from the controller method which is returning the actual blog content. Next use those ids in frontend buttons such that on click of the button new page uses the id passed to load the next or previous blog.

Defaulter
  • 358
  • 1
  • 4
  • 17
  • I add the rs.previous() for the travel expect from rs.next(), but when use rs.previous() then not show any data but when use rs.next then show the data. – Ravi Kant Sharma Dec 11 '19 at 12:13
  • I am not struts expert but I feel the page from where you tried previous and fail will be the first row, thus no previous existed for it. However it contain next row and therefore rs.next worked – Defaulter Dec 11 '19 at 12:18
  • I use here dynamically so I check for other links but same result thanks sir – Ravi Kant Sharma Dec 11 '19 at 12:31
  • I have done the same in my spring boot application. Where in database itself I maintain previous and next blog ids along with blog content. Same ids are mapped with buttons and make it working – Defaulter Dec 11 '19 at 14:51
  • I Use PHPMyAdmin for the database – Ravi Kant Sharma Dec 12 '19 at 03:59