If a trigger is configured to automatically set the primary key field with the next value from a sequence, then you can modify your INSERT statement as follows:
INSERT INTO table (field1, field2, field3)
VALUES (?, ?, ?)
RETURNING primary_key_field INTO ?
Then, add the parameter values for the INSERT, an output parameter at the end for the primary key, and execute the query.
After the query is executed, grab the value of the output parameter. It should contain the value of the primary_key_field.