Skip to content

Commit 919e10b

Browse files
Adding NoSuchElementException to solve SQ bug
1 parent 3e47beb commit 919e10b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/edu/ie3/datamodel/io/connectors/SqlConnector.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ public Iterator<Map<String, String>> getSqlIterator(ResultSet rs) {
162162
@Override
163163
public boolean hasNext() {
164164
try {
165-
return rs.next();
165+
boolean notEmpty = rs.isBeforeFirst() || rs.getRow() > 0;
166+
boolean notLastRow = !rs.isLast();
167+
return notEmpty && notLastRow;
166168
} catch (SQLException e) {
167169
log.error("Exception at extracting next ResultSet: ", e);
168170
closeResultSet(null, rs);
@@ -173,6 +175,12 @@ public boolean hasNext() {
173175
@Override
174176
public Map<String, String> next() {
175177
try {
178+
boolean valid = rs.next();
179+
180+
if (!valid)
181+
throw new NoSuchElementException(
182+
"There is no more element to iterate to in the ResultSet.");
183+
176184
return extractFieldMap(rs);
177185
} catch (SQLException e) {
178186
log.error("Exception at extracting ResultSet: ", e);

0 commit comments

Comments
 (0)