title: How to retrieve primary key value of selected row through JDBC (mariaDB)
body: <p>I have a problem getting the primary key value of a selected record with JDBC.
  I have HashMap with the table name as key and the primary key name as value and I'm iterating through it in order to find the table name the user has selected and get the primary key name. Up to that point everything works fine but when I try to get the primary key value it always returns 0.   </p>
  
  <p>The server I'm using is running on MariaDB 2.4.1 and I'm using Java 1.8. Below is the for loop responsible for the match of the user input and the assignment of the primary key name. Inside the try catch statement I try to get the primary key value but it returns always 0. The primary key is set in the database as auto incrementing and the value updates normally in the database. </p>
  
  <pre><code>for (Map.Entry hashMap : getTablesWithPrimaryKeys().entrySet()) {
      if (getTableName().compareTo(hashMap.getKey().toString()) == 0) {
          setPrimaryKey((String)hashMap.getValue());
          System.out.println(getPrimaryKey());
  
          try {
              PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + tableName, Statement.RETURN_GENERATED_KEYS);
              statement.executeQuery();
              ResultSet resultSet = statement.getGeneratedKeys();
  
              if (resultSet.next()) {
                  setPrimaryKeyValue(resultSet.getLong(1));
                  System.out.println(getPrimaryKeyValue());
              }
  
              connection.close();
          } catch (SQLException exception) {
              exception.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>I'm not getting an exceptions thrown so there is something that I'm missing for sure here. Any help please?</p>