下面是将值插入到一个表中的示例(MemberRecord)
//CreateUser method
public boolean createUser(){
boolean success = false;
DBController db = new DBController();
db.getConnection();
String sql = "INSERT INTO MemberRecord(id, name, email, contactNo, password, gender, nationality, dateOfBirth, address, postalCode, secQues, secAns, userType)";
sql += "VALUES('" + id + "','" + name + "','" + email + "','" + cNo + "','" + pwd + "','" +gen + "','" + nationality + "','" + dob + "','" + address + "','" + pCode + "','" + secQuestion +"','"+secAnswer +userType + "')";
if (db.updateRequest(sql)==1) success = true;
db.terminate();
return success;
}
如何将值插入到 2 个表中?当我尝试下面的代码时,我得到了重复的变量。即使我更改变量名称,它仍然会给我错误。
//CreateUser method
public boolean createUser(){
boolean success = false;
DBController db = new DBController();
db.getConnection();
String sql = "INSERT INTO MemberRecord(id, name, email, contactNo, password, gender, nationality, dateOfBirth, address, postalCode, secQues, secAns, userType)";
sql += "VALUES('" + id + "','" + name + "','" + email + "','" + cNo + "','" + pwd + "','" +gen + "','" + nationality + "','" + dob + "','" + address + "','" + pCode + "','" + secQuestion +"','"+secAnswer +userType + "')";
String sql = "INSERT INTO PaymentDetails(creditCardNo,creditCardType,expiryDate,CVV)";
sql += "VALUES('" + cCardNo + "','" + cCardType + "','" + expiryDate + "','" + cvv + "')";
if (db.updateRequest(sql)==1) success = true;
db.terminate();
return success;
}