Problem in dealing with multiple tables

General discussion on technical and managerial topics
no avatar
ashraf_raheem
 
Posts: 1
Joined: Mon Aug 31, 2009 7:20 am

Problem in dealing with multiple tables

by ashraf_raheem » Mon Aug 31, 2009 7:29 am

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

no avatar
markcollins
 
Posts: 2
Joined: Sat Aug 14, 2010 10:51 am

by markcollins » Sat Aug 14, 2010 11:00 am

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

no avatar
sakshi
 
Posts: 2
Joined: Tue Jun 12, 2012 5:40 pm

insertion in multiple tables

by sakshi » Tue Jun 12, 2012 5:49 pm

write separate query for insertion in each table

Return to General Discussion

cron