简体   繁体   中英

“Current position is after the last row” when ResultSet#getRow() returns 1

In MySQL ResultSet#getRow() returns < 1 when cursor position is after the last row. I just switched to MariaDB. I'm calling ResultSet#next() and after that ResultSet#getRow() . When the result set is empty ResultSet#getRow() returns 1 for MariaDB.

There is a lot of code to change if this really is how MariaDB works. Or am I doing something wrong and the problem exists only for me?

ResultSet is java.sql.ResultSet . MariaDB version is 10.0.14 on RHEL 7.0. I'm using mariadb-java-client-1.1.7.jar with Tomcat 8.0.15 and Java 8.

It is a bug in MariaDB. I'm pretty sure, by looking at their source, that if you called another next() , you'll get 2 and so on. This is how they implement next() in their CachedResultSet .

public boolean next() throws IOException, QueryException{
    rowPointer++;
    return rowPointer < resultSet.size();
}

And from looking at their StreamingResultSet code, you're not going to be any happier if you switch to streaming result sets, as those will throw an exception if you call getRow() .

I would advise you to change your code so that it checks the result of next() rather than relying on getRow() which, according to the JDBC documentation, is an optional method. Even if you report this bug to the developers of MariaDB and they fix it, you'll run into trouble as soon as your result sets are big enough for you to switch to their streaming mode (by changing the statement's fetch size). And if you switch to any other database that does not implement getRow() you'll run into similar trouble.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM