@Test(expected = RuntimeException.class) public void testDelete() throws Exception { Statement s = connection.createStatement(); ResultSet r = s.executeQuery(COUNT_SQL); r.next(); int rows = r.getInt(1); assertEquals(3, rows); UserDAO dao = new SQLUserDAO(connection); User user = new User("Denzler", "Christoph"); user.setId(42); dao.delete(user); IDataSet databaseDataSet = tester.getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable("CLIENTS"); InputStream stream = this.getClass().getResourceAsStream("UserDaoTestResult.xml"); IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(stream); ITable expectedTable = expectedDataSet.getTable("CLIENTS"); assertEquals(expectedTable, actualTable); connection.close(); dao.delete(user); }
@Override public void delete(IUser user) { try { PreparedStatement ps = connection.prepareStatement(DELETE_SQL); ps.setInt(1, user.getId()); ps.execute(); ps.close(); } catch (SQLException e) { throw new RuntimeException(e); } }
SQLUserDAO implements UserDAO { @Override public void delete(IUser user) { try { PreparedStatement ps = connection.prepareStatement(DELETE_SQL); ps.setInt(1, user.getId()); ps.execute(); ps.close(); } catch (SQLException e) { throw new RuntimeException(e); } } }
SQLUserDAO implements UserDAO { @Override public void delete(IUser user) { try { PreparedStatement ps = connection.prepareStatement(DELETE_SQL); ps.setInt(1, user.getId()); ps.execute(); ps.close(); } catch (SQLException e) { throw new RuntimeException(e); } } SQLUserDAO(Connection c); }
SQLUserDAO implements UserDAO { @Override public void delete(IUser user) { try { PreparedStatement ps = connection.prepareStatement(DELETE_SQL); ps.setInt(1, user.getId()); ps.execute(); ps.close(); } catch (SQLException e) { throw new RuntimeException(e); } } SQLUserDAO(Connection c); @Override void delete(IUser user); @Override List<IUser> getAll(); @Override IUser getById(int id); @Override List<IUser> getByName(String name); @Override void saveOrUpdate(IUser user); }
SQLUserDAO implements UserDAO { @Override public void delete(IUser user) { try { PreparedStatement ps = connection.prepareStatement(DELETE_SQL); ps.setInt(1, user.getId()); ps.execute(); ps.close(); } catch (SQLException e) { throw new RuntimeException(e); } } SQLUserDAO(Connection c); @Override void delete(IUser user); @Override List<IUser> getAll(); @Override IUser getById(int id); @Override List<IUser> getByName(String name); @Override void saveOrUpdate(IUser user);  }