Ask about added to many tables with duplicate data

http://stackoverflow.com/questions/26786246/how-to-parse-many-xml-files-with-cdata-in-a-folder-and-import-to-mysql-using-j/26788580

Dear Michael Minella, thank you for your guidance. 

I have another problems to ask: 
- Now we have 5 tables (actors, directors, films, film_actors, film_directors). Each director can have more than 1 film, so I want to implement the program that will insert new director into "directors" table and get the id use to insert into "film_directors" table. If director has already existed, the program will get the id and insert into "film_directors" table. Actor is similar.

Example: With 2 files (AVATAR.xml, TITANIC.xml), I want to insert into database like this:
--- Table "films":
AVATAR, AVATAR 2009, 7.9
TITANIC, TITANIC 1997, 7.7
--- Table "director":
1, James Cameron
--- Table "film_directors":
AVATAR, 1
TITANIC, 1

Would you please help me?

Best regards,
Samuel Wilsone