Hi, I’m new to golang.I just created a programming file using the below code.
package main
import (
"database/sql"
_ "mysql-master"
"fmt"
)
func main() {
db, err := sql.Open("mysql", "user:pass@/database?charset=utf8")
checkErr(err)
// insert
stmt, err := db.Prepare("INSERT userinfo SET username=?,departname=?,created=?")
checkErr(err)
res, err := stmt.Exec("astaxie", "astaxie", "2012-12-09")
checkErr(err)
id, err := res.LastInsertId()
checkErr(err)
fmt.Println(id)
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
when I was using the command like this go run insert-data.go, it inserts a new row into the database.
How can I use the same command in ubuntu crontab?. Is it possible?
And i know that there is a proper method for cron, but I want to use it like this.
Help me please