title: Apache Derby ID column should auto increment one by one - but it does not, why?
body: <p>I'm trying to create an Apache Derby-Table and to insert data in it by the JDBC-interface.</p>
  
  <p>Here is a short excerpt of my implementation:</p>
  
  <pre><code>public class SQLDatabase {
  
      private Connection connection = null;
      public final static String HOME_DIRECTORY = System.getProperty("user.home");
      public final static String TABLE_NAME = "PORPHYRIE";
  
      public SQLDatabase() {
  
          setConnection();
          if (!(isTableExisting(TABLE_NAME))) {
  
              createTable();
          }
  
      }
  
  
  
  
      // OTHER
  
      public void createTable() {
          String statement = "CREATE TABLE PORPHYRIE("
                  + "ID int NOT NULL GENERATED ALWAYS AS IDENTITY"
                  + "(START WITH 1,INCREMENT BY 1)," + "ENTRYDATE DATE NOT NULL,"
                  + "DRUGTYPE varchar(255) NOT NULL,"
                  + "UPPERLIMIT DOUBLE NOT NULL," + "NORMOSANG BOOLEAN NOT NULL,"
                  + "MENSTRUATION BOOLEAN NOT NULL,"
                  + "DRUGAMOUNT_MG DOUBLE NOT NULL,"
                  + "DRUGAMOUNT_ML DOUBLE NOT NULL,"
                  + "AMPOULE_NUMBERS DOUBLE NOT NULL,"
                  + "RECORDDATE DATE NOT NULL," + "PRIMARY KEY(ID)" + ")";
          updateStatement(statement);
      }
  
      public void dropTable() {
          String statement = "DROP TABLE PORPHYRIE";
          updateStatement(statement);
      }
  
      public void addData(EntryPoint entry) {
          DrugAmount drugAmount = entry.getDrugAmountObject();
          SimpleDateFormat form = new SimpleDateFormat("dd.MM.yyyy");
          String statement = "INSERT INTO PORPHYRIE (ENTRYDATE,DRUGTYPE,UPPERLIMIT,NORMOSANG,MENSTRUATION,DRUGAMOUNT_MG,DRUGAMOUNT_ML,AMPOULE_NUMBERS,RECORDDATE)"
                  + " values('"
                  + form.format(entry.getEntryDate().getTime())
                  + "','"
                  + entry.DRUG_TYPE_DOLANTIN
                  + "',"
                  + entry.DRUG_UPPER_LIMIT
                  + ","
                  + entry.getNormoSang()
                  + ","
                  + entry.getMenstruation()
                  + ","
                  + drugAmount.getAmpoulesInMG()
                  + ","
                  + drugAmount.getAmpoulesInML()
                  + ","
                  + drugAmount.getNumberOfAmpoules() + ",CURRENT_DATE)";
          System.out.println("Add data!");
          updateStatement(statement);
      }
  
  
     private void setConnection() {
          try {
              Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
              connection = DriverManager.getConnection("jdbc:derby:"
                      + HOME_DIRECTORY + "\\MyDB;create=true");
          } catch (ClassNotFoundException | SQLException e) {
              e.printStackTrace();
          }
      }
      private void updateStatement(String statementString) {
          try {
              PreparedStatement preparedStatement = getConnection()
                      .prepareStatement(statementString);
              preparedStatement.executeUpdate();
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>This is what I get:</p>
  
  <p><img src="https://i.stack.imgur.com/gXidS.png" alt="enter image description here"></p>
  
  <p>What is here the problem with the ID column?</p>
  
  <p>The first time when a SQL-Database object is created, is should create the table, which works fine.
  Then you should able to insert some data by the addData()-method, which also looks fine.
  But if you create an new SQL-Database Object and use the addData-method() within, then it adds the data (row five in the picture above) but do not auto-increment correctly. What is wrong here? </p>