I had the same problem, and as far as I can tell, there is no way to create a new primary key to an existing Apache Derby database. Derby does not allow you to add a column with GENERATED as an attribute.
Here's the method I found has worked the best.
Based on the original table:
CREATE TABLE contacts (firstname varchar(50), lastname varchar(50),
address varchar(50), phone1 varchar(14), phone2 varchar(14) );
Which looks like:
firstname lastname address phone1 phone2
rich bush 27 oak hill dr 11932035551234 11932035551234
Create a new table with the same structure, in addition to having the primary key.
CREATE TABLE contactsTemp
(primary_key INT not null GENERATED ALWAYS as identity,
firstname varchar(50), lastname varchar(50),
address varchar(50), phone1 varchar(14), phone2 varchar(14))
Breaking down the primary_key field. The first two are standard SQL keywords. The key will be an integer, and can't be null. Apache DB uses the keyword generated as their AUTO_GENERATED. There's two keywords that can follow generated ALWAYS and AS DEFAULT. Always means that it can't be manually entered, AS DEFAULT means it will be auto, unless you specify a number. Per the Apache spec
Copy data into new table via a INSERT
insert into contactsTemp (firstname, lastname, address , phone1 , phone2 )
SELECT firstname, lastname, address , phone1 , phone2 from contacts
Now remove the original contacts table
DROP TABLE contacts
Rename contactsTemp to contacts
RENAME TABLE contactstemp TO contacts