ResultSet rs = stmt.executeQuery("SELECT * FROM Users WHERE user_id=1"); if (rs.next()) { String userName = rs.getString("username"); if (rs.wasNull()) { System.out.println("User name was null"); } else { System.out.println("User name is: " + userName); } }
ResultSet rs = stmt.executeQuery("SELECT AVG(salary) FROM Employees"); if (rs.next()) { double averageSalary = rs.getDouble(1); if (rs.wasNull()) { System.out.println("Average salary was null"); } else { System.out.println("Average salary is: " + averageSalary); } }The java.util.ResultSet package is part of the Java standard library, so it does not require any additional package imports.