0
pstmt = conn.prepareStatement(SLCMQueryConstant.SELECT_ROLE_FOR_MAP);
pstmt.setInt(1, roleid);
pstmt.setInt(2, pageid);

rs = pstmt.executeQuery();

if (rs.next()) {
    PageDTO PageDTo = new PageDTO();
    PageDTo.setRolePageMapID(rs.getInt("Role_Page_Map_ID"));
    System.out.println(rs.getInt("Role_Page_Map_ID"));
    if (rs.getInt("Role_Page_Map_ID") == 0) {
        String query = SLCMQueryConstant.INSERT_INTO_ROLE_PAGE_MAP;
        int count = 1;
        pstmt = conn.prepareStatement(query);
        pstmt.setInt(count++, pageid);
        pstmt.setInt(count++, roleid);
        pstmt.executeUpdate();
        System.out.println(conn.getAutoCommit());
        conn.commit();
    } else {
        String query = SLCMQueryConstant.REUPDATE_INTO_ROLE_PAGE_MAP;
        int count = 1;
        pstmt = conn.prepareStatement(query);
        pstmt.setInt(count++, pageid);
        pstmt.setInt(count++, roleid);
        pstmt.executeUpdate();
        System.out.println(conn.getAutoCommit());
        conn.commit();
    }

}

in particular code,if table doesn't found entry corresponds to roleid and pageid then while is not executing if an entry found then update is happen. How to do insert operation if table doesn't found role_Page_Map_ID?

1 Answer 1

1
if (rs.next()) {

     //Do something
}
else {
    INSERT
}
Sign up to request clarification or add additional context in comments.

1 Comment

I have done. but my reputation is below an average as I am new joiner.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.