I just catch this "EmptyResultDataAccessException"
public Myclass findOne(String id){
try {
Myclass m = this.jdbcTemplate.queryForObject(
"SELECT * FROM tb_t WHERE id = ?",
new Object[]{id},
new RowMapper<Myclass>() {
public Myclass mapRow(ResultSet rs, int rowNum) throws SQLException {
Myclass m = new Myclass();
m.setName(rs.getString("name"));
return m;
}
});
return m;
} catch (EmptyResultDataAccessException e) { // result.size() == 0;
return null;
}
}
then you can check:
if(m == null){
// insert operation.
}else{
// update operation.
}