So I'm trying to enter this string into a mysql database using a sql driver. I get this error -
Do?a Merced Elementary
panic: Error 1366: Incorrect string value: '\x96a Mer...' for column 'name' at row 1
I thought about excluding this entry, but haven't been able to do so. I've tried -
if !strings.ContainsAny(splitStr[2], "U+0303") {
if !strings.ContainsAny(splitStr[2], '\x96') {
but that has not worked.
It would be better to have mysql deal with this, but I'm not sure how.
Any suggestions?
EDIT
This is how I connect to my db
db, err := sql.Open("mysql", "psanker:123@/education_data")
err = db.Ping()
db.SetMaxOpenConns(0)
check(err)
if err != nil {
fmt.Println("Failed to prepare connection to database")
log.Fatal("Error:", err.Error())
}
This is where my issue comes
districtResult, err := db.Exec("INSERT INTO districts(name) VALUES(?)", strings.TrimSpace(splitStr[2]))
check(err)
Output of SHOW CREATE TABLE
---------------------------------+
| Table | Create Table |
+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| districts | CREATE TABLE `districts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |