@Test public void shouldSelectList() throws Exception { DataSource ds = createUnpooledDataSource(JPETSTORE_PROPERTIES); runScript(ds, JPETSTORE_DDL); runScript(ds, JPETSTORE_DATA); try (Connection connection = ds.getConnection()) { SqlRunner exec = new SqlRunner(connection); List<Map<String, Object>> rows = exec.selectAll("SELECT * FROM PRODUCT"); assertEquals(16, rows.size()); } }
public List<Map<String, Object>> selectAll(String sql, Object... args) throws SQLException { PreparedStatement ps = connection.prepareStatement(sql); try { setParameters(ps, args); ResultSet rs = ps.executeQuery(); return getResults(rs); } finally { try { ps.close(); } catch (SQLException e) { } } }
SqlRunner { public List<Map<String, Object>> selectAll(String sql, Object... args) throws SQLException { PreparedStatement ps = connection.prepareStatement(sql); try { setParameters(ps, args); ResultSet rs = ps.executeQuery(); return getResults(rs); } finally { try { ps.close(); } catch (SQLException e) { } } } }
SqlRunner { public List<Map<String, Object>> selectAll(String sql, Object... args) throws SQLException { PreparedStatement ps = connection.prepareStatement(sql); try { setParameters(ps, args); ResultSet rs = ps.executeQuery(); return getResults(rs); } finally { try { ps.close(); } catch (SQLException e) { } } } SqlRunner(Connection connection); }
SqlRunner { public List<Map<String, Object>> selectAll(String sql, Object... args) throws SQLException { PreparedStatement ps = connection.prepareStatement(sql); try { setParameters(ps, args); ResultSet rs = ps.executeQuery(); return getResults(rs); } finally { try { ps.close(); } catch (SQLException e) { } } } SqlRunner(Connection connection); void setUseGeneratedKeySupport(boolean useGeneratedKeySupport); Map<String, Object> selectOne(String sql, Object... args); List<Map<String, Object>> selectAll(String sql, Object... args); int insert(String sql, Object... args); int update(String sql, Object... args); int delete(String sql, Object... args); void run(String sql); void closeConnection(); }
SqlRunner { public List<Map<String, Object>> selectAll(String sql, Object... args) throws SQLException { PreparedStatement ps = connection.prepareStatement(sql); try { setParameters(ps, args); ResultSet rs = ps.executeQuery(); return getResults(rs); } finally { try { ps.close(); } catch (SQLException e) { } } } SqlRunner(Connection connection); void setUseGeneratedKeySupport(boolean useGeneratedKeySupport); Map<String, Object> selectOne(String sql, Object... args); List<Map<String, Object>> selectAll(String sql, Object... args); int insert(String sql, Object... args); int update(String sql, Object... args); int delete(String sql, Object... args); void run(String sql); void closeConnection(); static final int NO_GENERATED_KEY; }