How do I check if cursor is in the first row?

When iterating the scrollable result sets you can check whether you are in the beginning of the result set or not. The isBeforFirst() method check if the cursor position is before the first row in the result set, if yes this method will return true, otherwise it will return false.

package org.kodejava.example.sql;

import java.sql.*;

public class ScrollableIsBeforeFirstExample {
    public static final String URL = "jdbc:mysql://localhost/testdb";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "";

    public static void main(String[] args) throws Exception {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);

            Statement stmt = conn.createStatement(

            ResultSet rs = stmt.executeQuery("SELECT * FROM products");

            // Check if we are at the beginning of the result set.
            if (rs.isBeforeFirst()) {
                System.out.println("We are at the beginning.");
        } catch (SQLException e) {
        } finally {
            if (conn != null) {