Created
June 4, 2012 07:13
-
-
Save benelog/2866872 to your computer and use it in GitHub Desktop.
Spring jdbc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void batchUpdateTest(){ | |
SqlParameterSource[] source = new SqlParameterSource[]{new MapSqlParameterSource("id", 1), new MapSqlParameterSource("id", 2),new MapSqlParameterSource("id", 3)}; | |
int[] updated = simpleJdbcTemplate.batchUpdate("update perform set id=:id where id = :id", source); | |
System.out.println(Arrays.toString(updated)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Integer insertAndGetSeq(Book book) { | |
SqlParameterSource params = new BeanPropertySqlParameterSource(book); | |
KeyHolder keyHolder = new GeneratedKeyHolder(); | |
jdbc.update(WidgetSqls.insert, params, keyHolder); | |
return keyHolder.getKey().intValue(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Integer insertAndGetSeq(Book input) { | |
SqlParameterSource params = new BeanPropertySqlParameterSource(input); | |
SimpleJdbcInsert insertAction = new SimpleJdbcInsert(dataSource).withTableName("book"); | |
insertAction.setGeneratedKeyName("seq"); | |
KeyHolder keyHolder = insertAction.executeAndReturnKeyHolder(params); | |
return keyHolder.getKey().intValue(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void insert(Book input) { | |
SqlParameterSource params = new BeanPropertySqlParameterSource(input); | |
SimpleJdbcInsert insertAction = new SimpleJdbcInsert(ds).withTableName("book"); | |
insertAction.execute(params); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment