title: Getting last auto increment value in database
body: <p>I am trying to retrieve the auto increment value of last inserted data in mySQL. Here is my code:</p>
  
  <pre><code>public int getAutoIncrementProductID() {
      ResultSet rs = null;
      DBController db = new DBController();
      db.getConnection();
      int autoIncKeyFromFunc = -1;
      rs = db.readRequest("SELECT LAST_INSERT_ID()");
      try {
          if (rs.next()) {
              autoIncKeyFromFunc = rs.getInt(1);
              System.out.println("AUTO ID IS " + autoIncKeyFromFunc);
              rs.close();
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
      db.terminate();
      return autoIncKeyFromFunc;
  }
  </code></pre>
  
  <p>However, these codes keep returning me 0 value although the auto increment column in database is keep increasing. It just wont get the auto increment value of last inserted data. Anybody could help?</p>