Develop a Go program that connects to a MySQL database and inserts a set of records into a "products" table. The program should read the product data from a JSON file, which contains an array of objects with properties: "name", "description", "price", and "quantity". Additionally, implement error handling for cases where the JSON file is malformed or the database connection fails.
PLAINFORMAT
package main

import (
	"database/sql"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"

	_ "github.com/go-sql-driver/mysql"
)

type Product struct {
	Name        string  `json:"name"`
	Description string  `json:"description"`
	Price       float64 `json:"price"`
	Quantity    int     `json:"quantity"`
}

func main() {
	data, err := ioutil.ReadFile("products.json")
	if err != nil {
		log.Fatal(err)
	}

	var products []Product
	err = json.Unmarshal(data, &products)
	if err != nil {
		log.Fatal(err)
	}

	db, err := sql.Open("mysql", "username:password@tcp(localhost:3306)/dbname")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	for _, p := range products {
		insertProduct(p, db)
	}
}

func insertProduct(product Product, db *sql.DB) {
	stmt, err := db.Prepare("INSERT INTO products(name, description, price, quantity) VALUES(?, ?, ?, ?)")
	if err != nil {
		log.Fatal(err)
	}
	defer stmt.Close()

	res, err := stmt.Exec(product.Name, product.Description, product.Price, product.Quantity)
	if err != nil {
		log.Fatal(err)
	}

	lastID, err := res.LastInsertId()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Inserted product with ID: %d\n", lastID)
}