Use try-with-resources for closing cursor.