import org.springframework.jdbc.core.jdbctemplate;import org.springframework.jdbc.core.rowmapper; import org.springframework.jdbc.core.preparedstatementcreator;import org.springframework.jdbc.support.generatedkeyholder;import org.springframework.jdbc.support.keyholder; public class jdbctest{ //setter and getter / /..... //function final string sql= "..."; keyholder keyholder = new generatedkeyholder (); Jdbctemplate.update (New preparedstatementcreator () { @Override public PreparedStatement Createpreparedstatement (connection connection) throws SQLException{ preparedstatement ps&nbsP;= connection.preparestatement (sql, preparedstatement.return_generat ed_keys); ps.setstring (1, "AreaName"); ps.setint (2, 98); //.... return ps; } }, keyholder); Return keyholder.getkey (). Intvalue ();}
JdbcTemplate inserting MySQL and returning the primary key ID