JdbcService { public int insert(String table, String columns, Object... args) { String sql = String.format("INSERT INTO `%s` (%s) VALUES (%s)", table, columns, StringUtils.repeat("?", ",", args.length)); return jdbc().update(sql, args); } JdbcService(DataSource dataSource); JdbcTemplate jdbc(); NamedParameterJdbcTemplate jdbcn(); DataSource getDataSource(); T queryForObject(String sql, Class<T> type); T queryForObject(String sql, Class<T> type, Object... args); Boolean queryForBoolean(String sql, Object... args); long count(String table); long count(String table, String where, Object... args); int insert(String table, String columns, Object... args); int insert(String table, String[] columns, Object[] args); int insert(String table, Object... args); int[] insert(String table, Collection<String> columns, SqlParameterSource[] records); int[] insert(Table table, List<IndexRecord> records); int[] update(String table, Collection<String> columns, String whereClause, SqlParameterSource[] records); int[] update(Table table, List<IndexRecord> records); int[] delete(String table, String whereClause, SqlParameterSource[] records); int[] delete(Table table, List<IndexRecord> records); int delete(String table, String whereClause, Object... args);  }
@SuppressWarnings("unchecked") @Test public void insert_indexRecordsIntoTable() throws Exception { List<IndexRecord> records = getRecords(); service.insert(table, records); List<Map<String, Object>> rows = jdbc.queryForList("SELECT * FROM `TEST`"); Map<String, Object> row; row = rows.get(0); assertEquals(1L, row.get("ID")); assertEquals("Arthur", row.get("NAME")); assertEquals(42, row.get("AGE")); row = rows.get(1); assertEquals(2L, row.get("ID")); assertEquals("Ford", row.get("NAME")); assertNull(row.get("AGE")); }