![Learn Data Structures and Algorithms with Golang](https://wfqqreader-1252317822.image.myqcloud.com/cover/744/36698744/b_36698744.jpg)
上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()
}