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.