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

The InsertCustomer method

The INSERT operation is as follows. The InsertCustomer method takes the Customer parameter and creates a prepared statement for the INSERT statement. The statement is used to execute the insertion of customer rows into the table, as shown in the following snippet:

// 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()


}

Let's take a look at the variadic functions in the next section.