INSERT INTO using a value from another table

nick2price

Registered User.
Local time
Today, 04:42
Joined
Sep 24, 2008
Messages
14
I am using java with jdbc to perform my sql operations. I have a primary key in one table and i want to set it as a foriegn key in another. I am trying to do somthing like this
insert into events(name, meet_id) select '100 yard dash', id from meets where name = 'melrose games';

In java i am attempting somthing like this
Code:
String sql = "INSERT INTO tblEvent (Event_Name, Meet_ID) VALUES (?) " + 
"SELECT eveType2, " +
"ID FROM tblMeet " +
"WHERE Meet_Name='Wembley' ";
ps = con.prepareStatement(sql);
ps.setString(1, eveType2);
ps.executeUpdate();

Where eveType2 is a parsed variable and ID should be a value retrieved from tblMeet. How would i do somthing like the above query in java?
 

Users who are viewing this thread

Back
Top Bottom