www.tutorialspoint.com Forum Index
Register FAQMemberlistUsergroupsTutorials PointLog in
Reply to topic Page 1 of 1
Problem in dealing with multiple tables
Author Message
Reply with quote
Post Problem in dealing with multiple tables 
hi,
i am trying to insert records in multiple tables.The tables are linked. i am implementing transaction sort of thing.please see the code and tell me what's wrong with the code.
"emp table has an auto increament field with the name "id". id is used as foreign key in rest of the tables"

public void insertEmp(EmpDao emp)
{
String qry1="insert into emp(fname,sname) values('"+emp.getFname()+"','"+emp.getSname()+"')";
String identity="select mysql_insert_id() from dual";
//String qry2="insert into contactdetail(id,address,phone,email) values("+rs.getInt(1)+",'"+emp.getAddress()+ "',"+emp.getPhone()+",'"+emp.getEmail()+"');";
//+"insert into skill values("+"select @@identity from dual;"+",'"+emp.getPskills()+"','"+emp.getMskills()+"','"+emp.getTskills()+"')";

try{
con=MyConnection.getConnection();
con.setAutoCommit(false);
stat=con.createStatement();
spt = con.setSavepoint("svpt1");
stat.execute(qry1);

stat.executeQuery(identity);

String qry2="insert into contactdetail(id,address,phone,email) values("+rs.getInt(1)+",'"+emp.getAddress()+ "',"+emp.getPhone()+",'"+emp.getEmail()+"')";
stat.execute(qry2);
con.commit();

}
catch(Exception e)
{
try{
con.rollback(spt);
}
catch(SQLException e1)
{}
}

View user's profile Send private message
Reply with quote
Post  
Thanks for the input. Don't believe even a single table would do it
since the data would reside in multiple columns, and any/all search
words could be in any of the columns.







______________________________________________________________________
Want to get-on Google's first page
and loads of traffic to your website?
Hire a SEO Specialist from Ocean Groups

View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum