package main
import (
"database/sql"
"fmt"
)
func ConnectDB() (db *sql.DB, err error) {
dbDriver := "mysql"
dbUser := "root"
dbPass := "nilpointer.net"
dbName := "nilpointer_db"
db, err = sql.Open(dbDriver, dbUser+":"+dbPass+"@/"+dbName)
return
}
func main() {
db, err := ConnectDB()
if err != nil {
fmt.Println(err)
} else {
rows, err2 := db.Query("select max(price) as max_price from mobile")
if err2 != nil {
fmt.Println(err2)
} else {
var max_price float64
for rows.Next() {
rows.Scan(&max_price)
}
fmt.Println("max price: ", max_price)
}
}
}