@Test public void testAddForums() throws Throwable { List<Forum> forums = new ArrayList<Forum>(); for(int i =0 ;i< 100000 ;i++){ Forum f1 = new Forum(); f1.setForumName("爱美妈妈"); f1.setForumDesc("减肥、塑身、化妆品"); forums.add(f1); } forumDao.addForums(forums); }
public void addForums(final List<Forum> forums) { final String sql = "INSERT INTO t_forum(forum_name,forum_desc) VALUES(?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return forums.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { Forum forum = forums.get(index); ps.setString(1, forum.getForumName()); ps.setString(2, forum.getForumDesc()); } }); }
ForumDao { public void addForums(final List<Forum> forums) { final String sql = "INSERT INTO t_forum(forum_name,forum_desc) VALUES(?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return forums.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { Forum forum = forums.get(index); ps.setString(1, forum.getForumName()); ps.setString(2, forum.getForumDesc()); } }); } }
ForumDao { public void addForums(final List<Forum> forums) { final String sql = "INSERT INTO t_forum(forum_name,forum_desc) VALUES(?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return forums.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { Forum forum = forums.get(index); ps.setString(1, forum.getForumName()); ps.setString(2, forum.getForumDesc()); } }); }  }
ForumDao { public void addForums(final List<Forum> forums) { final String sql = "INSERT INTO t_forum(forum_name,forum_desc) VALUES(?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return forums.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { Forum forum = forums.get(index); ps.setString(1, forum.getForumName()); ps.setString(2, forum.getForumDesc()); } }); }  @Autowired void setJdbcTemplate(JdbcTemplate jdbcTemplate); @Autowired void setNamedParameterJdbcTemplate(NamedParameterJdbcTemplate namedParameterJdbcTemplate); void initDb(); void addForum(final Forum forum); void addForumByNamedParams(final Forum forum); void addForums(final List<Forum> forums); Forum getForum(final int forumId); List<Forum> getForums(final int fromId, final int toId); }
ForumDao { public void addForums(final List<Forum> forums) { final String sql = "INSERT INTO t_forum(forum_name,forum_desc) VALUES(?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return forums.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { Forum forum = forums.get(index); ps.setString(1, forum.getForumName()); ps.setString(2, forum.getForumDesc()); } }); }  @Autowired void setJdbcTemplate(JdbcTemplate jdbcTemplate); @Autowired void setNamedParameterJdbcTemplate(NamedParameterJdbcTemplate namedParameterJdbcTemplate); void initDb(); void addForum(final Forum forum); void addForumByNamedParams(final Forum forum); void addForums(final List<Forum> forums); Forum getForum(final int forumId); List<Forum> getForums(final int fromId, final int toId);  }