When you call execute method by passing the data map of values, it would automatically query the metadata of the table into his it has to perform insert operation and builds a query and inserts the data.
StudentDao.java
public class SimpeStudentInsertDao; private SimpleJdbcInsert simpleJdbcInsert; public SimpleStudentInsertDao(DataSource dataSource) { this.simpleJdbcInsert = new SimpleJdbcInsert(dataSource); } public void insert(StudentBO student) { simpleJdbcInsert.setTableName(“STUDENT”); SqlParameterSource paramSource = new BeanPropertySqlParameterSource(student); simpleJdbcInsert.execute(paramSource); } public void insert(int id, String name) { simpleJdbcInsert.setTableName(“STUDENT”); Map<String, Object> data = new HashMap<String, Object>(); data.put(“STUDENT_ID”, student.getStudentId()); data.put(“NAME”, student.getStudentName()); simpleJdbcInsert.execute(data); } }
Thanks for reading. If you like this post please follow us for more updates about technology related updates.
No comments:
Post a Comment