I am trying to execute queries with Go, but I cannot manage to request any query, because it keeps giving me the same error over and over.
I have changed the query multiple times, but that doesn't seem to help. Also i have changed QueryRow in Query, unfortunately that doesn't help either.
func test123() {
db, err := sql.Open("mysql", "root:password@tcp(127.0.0.1:3306)/vitaintellectdb")
if err != nil {
panic(err.Error())
}
id := 1
var col string
sqlStatement := `SELECT naam FROM medewerker WHERE naam="jansen"`
row := db.QueryRow(sqlStatement, id)
err2 := row.Scan(&col)
if err2 != nil {
if err2 == sql.ErrNoRows {
fmt.Println("Zero rows found")
} else {
panic(err2)
}
}
}
QueryRow is designed to give you 1 row in return. Unfortunately the error is telling me that there should be no returns, I expect 1 row in return.
The error is telling you that you are passing an argument to QueryRow that it is not expecting.
Your SQL statement doesn't have any placeholders so isn't expecting any but you are giving it one of id. Just change:
row := db.QueryRow(sqlStatement, id)
to:
row := db.QueryRow(sqlStatement)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With