method: First realize Batchpreparedstatementse tter interface, and then call the JdbcTemplate batchUpdate (Sql,setter) operation, the parameter SQL is a precompiled statement, and the setter is an instance of BatchPreparedStatementSetter. Or use the internal anonymous class method.
BatchPreparedStatementSetter interface
Public Interface batchpreparedstatementsetter{ public int getbatchsize ();//Returns the size of the batch Public void setvalues (preparedstatement PS,int i);
// PS: We are going to set the value of the PreparedStatement
I: In this batch rollup, the index of the operation being performed, starting from 0
}
Implementation (Internal anonymous Class):
Jdbctemplate.batchupdate (SQL,NewBatchPreparedStatementSetter () { Public intgetbatchsize () {//TODO auto-generated Method Stub returnresourcelist.size (); Read the size of the data source list} Public voidSetvalues (PreparedStatement PS,intIthrowsSQLException {//TODO auto-generated Method StubResourcebean Resourcebean =(Resourcebean) resourcelist.get (i);//Read the list of source data to be inserted pstmt.setstring (1, Resourcebean.getid ()); Pstmt.setstring (2, Resourcebean.getname ()); Pstmt.setstring (3, Resourcebean.getauthor ()); ... ... } });