Java JDBC ResultSet create with try-with-resources
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { public static void queryDatabase() { String qry = "select recipe_num, name, description from recipes"; try (Connection conn = getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(qry);) { while (rs.next()) { String recipe = rs.getString("RECIPE_NUM"); String name = rs.getString("NAME"); String desc = rs.getString("DESCRIPTION"); System.out.println(recipe + "\t" + name + "\t" + desc); }// w w w.j a va2s .c o m } catch (SQLException e) { e.printStackTrace(); } } }