Spring JDBC Tips

Version: 4.3.1


For stored procedure, function

Cannot create one SimpleJdbcCall for many stored procedures/functions (once initialized, later change won’t work. For example, to call another stored procedure… )

public DataSource dataSource;

public Map<String, Object> callStoredProcedure(String procedureName, final Map<String, Object> params) {
 SimpleJdbcCall jdbcCall = new SimpleJdbcCall(dataSource).withProcedureName(procedureName);
 return jdbcCall.execute(params);


For query, insert, delete, stored procedure, function…

@Resource(name = "jdbcTemplate")
public JdbcTemplate jdbcTemplate;

public List<MyObject> find(String id) {
 List<MyObject> list = jdbcTemplate.query(FIND_BY_ID_SQL,
  new RowMapper<MyObject>() {
   public MyObject mapRow(ResultSet rs, int rowNum) throws SQLException {
    MyObject myObject = new MyObject();
    return myObject;
  }, id);




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s