Register • FAQ • Memberlist • Usergroups • Tutorials Point • Log in

| Page 1 of 1

Problem in dealing with multiple tables
Author | Message
--- | ---
ashraf_raheem Joined: 31 Aug 2009 Posts: 1 | 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)
{}
}
Mon Aug 31, 2009 7:29 am |
markcollins Joined: 14 Aug 2010 Posts: 2 | 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
Sat Aug 14, 2010 11:00 am |

Display posts from previous: |

| 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

Powered by phpBB © phpBB Group Design by Vjacheslav Trushkin for phpBBStyles.com