Fiona,
Basically you have two queries. So the high level approach is:
1) Query external database (database 1)
2) Loop through result set and store fields in variables (or List if multiple rows.)
3) Build sql
string for second query. I recommend using prepared statements so you can easily substitute in the values.
4) Run second query (database 2)
5) Loop through result set and process actual values
The logic behind separating the queries is so you can close the first connection sooner. Take a look at
Sun's JDBC tutorial to get started with JDBC.
For the future, I recommend posting this type of question in the JDBC forum since it is more about JDBC than session beans.