uhhmmm.... if you use e.g. hibernate, it will do it for you. Is a lot easier
You can call GraphSession.deleteProcessInstance on each instance you want to remove. Note that this method is somewhat slow due to cascading.
If you want mass deletion you can analyze the order of the statements executed by deleteProcessInstance and write a SQL script.