尝试一次将用户信息输入到2个表

时间:2018-04-25 13:21:09

标签: android-studio transactions azure-sql-database

我正在尝试通过用户输入同时向2个表添加数据,但是它所做的只是插入第一个表而不是第二个。该代码用于azure sql数据库

String query = "BEGIN TRANSACTION; 
INSERT INTO cc_customer (customer_id,customer_first_name,customer_surname,customer_tel_number,customer_cell_number,customer_status,employee_number) 
VALUES ('"+id.toString()+"','"+ name.toString()+"','"+ Lname.toString()+"','"+ Telnum.toString()+"','"+Cellnum.toString()+"','"+Status.toString()+"','"+Empnum.toString()+"');
"+" 
INSERT INTO cc_customer_address (customer_address_id,customer_building_number,customer_street,customer_suburb,customer_city,customer_zip_code) 
VALUES ('"+Cusnum.toString()+"','"+ Cusbuild.toString()+"','"+ Cusstr.toString()+"','"+ Cussub.toString()+"','"+Cuscity.toString()+"','"+Cuszip.toString()+"')COMMIT;";

1 个答案:

答案 0 :(得分:0)

这有效!!!!

String query = "BEGIN TRANSACTION INSERT INTO cc_customer(customer_id,customer_first_name,customer_surname,customer_tel_number,customer_cell_number,customer_status,employee_number) VALUES ('"+id.toString()+"','"+name.toString()+"','"+Lname.toString()+"','"+Telnum.toString()+"','"+Cellnum.toString()+"','"+Status.toString()+"','"+Empnum.toString()+"')"+"INSERT INTO cc_customer_address(customer_number,customer_building_number,customer_street,customer_suburb,customer_city,customer_zip_code) VALUES ('"+Cusnum.toString()+"','"+Cusbuild.toString()+"','"+Cusstr.toString()+"','"+Cussub.toString()+"','"+Cuscity.toString()+"','"+Cuszip.toString()+"') COMMIT";