Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet rs=st.executeQuery("select * from emp where deptno=31"); rs.last(); System.out.println("NoOfRows: "+rs.getRow());
the first line of code says that we can move anywhere in the result set (either to the first line, or to the last line or before the first line without having to move along the line, starting from the first line, which takes time). The second line of code retrieves the records matching the request, here I accept (25 entries), the third line of code moves the cursor to the last line, and the last line of code gets the number of the current line, which in my case is 25. if there are no entries, rs.last returns 0, and getrow moves the cursor to the first line, therefore, a returned negative value indicates the absence of entries in db
pradeep kumar Jul 30 '16 at 17:33 2016-07-30 17:33
source share