package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/denisenkom/go-mssqldb"
)
func main() {
connectString := "server=127.0.0.1;database=yndb;user id=sa;password=sql;port=8829;encrypt=disable"
println("Connection string=", connectString)
db, err := sql.Open("mssql", connectString)
defer db.Close()
println("Open Error:", err)
if err != nil {
log.Fatal(err)
}
// 执行SQL语句
rows, err := db.Query("select * from tunit")
if err != nil {
fmt.Println("query: ", err)
return
}
for rows.Next() {
var id string
var name int
rows.Scan(&id, &name)
fmt.Printf("id: %s \t name: %d\n", id, name)
}
println("closing connection")
db.Close()
}
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询