上QQ阅读APP看书,第一时间看更新
The InsertCustomer method
In the following code, the InsertCustomer method takes customer as a parameter to execute the SQL statement for inserting into the CUSTOMER table:
// InsertCustomer method with parameter customer
func InsertCustomer(customer Customer) {
var database *sql.DB
database= GetConnection()
var error error
var insert *sql.Stmt
insert,error = database.Prepare("INSERT INTO CUSTOMER(CustomerName,SSN) VALUES(?,?)")
if error != nil {
panic(error.Error())
}
insert.Exec(customer.CustomerName,customer.SSN)
defer database.Close()
}