ResultSset is important element when we are fetching the results from database. Generally we do null check or data exist before accessing the element. This will help us reduce some run-time errors. Simple way to check data exist or not is next() method in resultset
But there is a problem with this, When we call result.next() cursor will move to the next position. So we will be loosing first record in the result set.Now how can we check result set is empty or null without moving cursor.
isBeforeFirst() returns true only when any successful query execution returns ResultSet.isBeforeFirst method is good alternative for rs.next() interms of checking data.
ResultSet rs = stmt.executeQuery(query); while (rs.next()) { }
But there is a problem with this, When we call result.next() cursor will move to the next position. So we will be loosing first record in the result set.Now how can we check result set is empty or null without moving cursor.
ResultSet rs = stmt.executeQuery(query); if(rs.isBeforeFirst()){ }
isBeforeFirst() returns true only when any successful query execution returns ResultSet.isBeforeFirst method is good alternative for rs.next() interms of checking data.
0 Comments
Post a Comment