This functionality could be auto-enabled for all tables or only for huge tables with many rows, also will be great to ask about the stat in alternative ways rather than proposed below:
// Your original query
val originalQuery = "SELECT * FROM your_table_name WHERE column_name = 'some_value'"
// Query to count the number of rows
val countQuery = "SELECT COUNT(*) as count FROM (" + originalQuery + ") AS count_query"
// Create a statement and execute the count query
val countStatement = connection.createStatement()
val countResultSet = countStatement.executeQuery(countQuery)
// Get the row count
val rowCount = 0
if (countResultSet.next()) {
rowCount = countResultSet.getInt("count")