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)
{}
}