{ stmt.setQueryTimeout(timeoutSeconds); } rs = stmt.executeQuery(query); if (rs.next()) { res = rs.getLong(1); // NULL result is interpreted as 0 with getLong() if (rs.wasNull()) { res = defaultVal; } } } catch (SQLException e) { LOG.warn("Error executing query : " + query + " Exception=" + e.getMessage() ); LOG.warn("Returning default value: " + defaultVal); }