title: How to get generated ID after I inserted into a new data record in database using Spring JDBCTemplate?
body: <p>I got a very common question when I was using Spring JDBCTemplate, I want to get the ID value after I inserted a new data record into database, this ID value will be referred to another related table. I tried the following way to insert it, but I always return 1 rather than its real unique ID. (I use MySQL as the database)</p>
  
  <pre><code>public int insert(BasicModel entity) {
      String insertIntoSql = QueryUtil.getInsertIntoSqlStatement(entity);
  
      log.info("SQL Statement for inserting into: " + insertIntoSql);
  
      return this.jdbcTemplate.update(insertIntoSql);
  }
  </code></pre>