Learn Data Structures and Algorithms with Golang
上QQ阅读APP看书,第一时间看更新

The UpdateCustomer method

The UpdateCustomer method prepares the UPDATE statement by passing the CustomerName and SSN from the customer object; this is shown in the following code:

// Update Customer method with parameter customer
func UpdateCustomer(customer Customer) {
var database *sql.DB
database= GetConnection()
var error error
var update *sql.Stmt
update,error = database.Prepare("UPDATE CUSTOMER SET CustomerName=?, SSN=? WHERE CustomerId=?")
if error != nil {
panic(error.Error())
}
update.Exec(customer.CustomerName,customer.SSN,customer.CustomerId)
defer database.Close()
}