其他的增删改都正常,就是查询代码出错
~~~
func select1(w http.ResponseWriter, r *http.Request) {
db, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/test?charset=utf8")
checkErr(err)
//rows,err :=db.Query("select uid ,age form user_list where user ='guest'")
rows, err := db.Query("select * from user_list")
checkErr(err)
for rows.Next() {
var uid int
var user string
//var age int
rows.Columns()
err = rows.Scan(&uid, &user)
checkErr(err)
fmt.Fprintln(w, uid)
fmt.Fprintln(w, user)
//fmt.Fprintln(w, age)
}
//关闭数据库
db.Close()
}
~~~
<a href="/user/channel" title="@channel">@channel</a>
这个错误在liteide看到的 不太懂
~~~
c:/go/bin/go.exe build -i [D:/GoPath/src/liteIdeTest]
成功: 进程退出代码 0.
D:/GoPath/src/liteIdeTest/liteIdeTest.exe [D:/GoPath/src/liteIdeTest]
sql: expected 4 destination arguments in Scan, not 2
sql: expected 4 destination arguments in Scan, not 2
2017/09/11 13:56:43 http: panic serving 127.0.0.1:17112: sql: expected 4 destination arguments in Scan, not 2
goroutine 18 [running]:
net/http.(*conn).serve.func1(0xc04204adc0)
c:/go/src/net/http/server.go:1697 +0xd7
panic(0x732ae0, 0xc042156060)
c:/go/src/runtime/panic.go:491 +0x291
main.checkErr(0x940e60, 0xc042156060)
D:/GoPath/src/liteIdeTest/main.go:145 +0xab
main.select1(0x9457e0, 0xc04212e000, 0xc042124000)
D:/GoPath/src/liteIdeTest/main.go:46 +0x1da
net/http.HandlerFunc.ServeHTTP(0x7b5d08, 0x9457e0, 0xc04212e000, 0xc042124000)
c:/go/src/net/http/server.go:1918 +0x4b
net/http.(*ServeMux).ServeHTTP(0x97dfc0, 0x9457e0, 0xc04212e000, 0xc042124000)
c:/go/src/net/http/server.go:2254 +0x137
net/http.serverHandler.ServeHTTP(0xc042080c30, 0x9457e0, 0xc04212e000, 0xc042124000)
c:/go/src/net/http/server.go:2619 +0xbb
net/http.(*conn).serve(0xc04204adc0, 0x945ca0, 0xc04204e240)
c:/go/src/net/http/server.go:1801 +0x724
created by net/http.(*Server).Serve
c:/go/src/net/http/server.go:2720 +0x28f
2017/09/11 13:56:43 http: panic serving 127.0.0.1:17114: sql: expected 4 destination arguments in Scan, not 2
goroutine 34 [running]:
net/http.(*conn).serve.func1(0xc04215c140)
c:/go/src/net/http/server.go:1697 +0xd7
panic(0x732ae0, 0xc042046d50)
c:/go/src/runtime/panic.go:491 +0x291
main.checkErr(0x940e60, 0xc042046d50)
D:/GoPath/src/liteIdeTest/main.go:145 +0xab
main.select1(0x9457e0, 0xc04219c000, 0xc042124100)
D:/GoPath/src/liteIdeTest/main.go:46 +0x1da
net/http.HandlerFunc.ServeHTTP(0x7b5d08, 0x9457e0, 0xc04219c000, 0xc042124100)
c:/go/src/net/http/server.go:1918 +0x4b
net/http.(*ServeMux).ServeHTTP(0x97dfc0, 0x9457e0, 0xc04219c000, 0xc042124100)
c:/go/src/net/http/server.go:2254 +0x137
net/http.serverHandler.ServeHTTP(0xc042080c30, 0x9457e0, 0xc04219c000, 0xc042124100)
c:/go/src/net/http/server.go:2619 +0xbb
net/http.(*conn).serve(0xc04215c140, 0x945ca0, 0xc04204e380)
c:/go/src/net/http/server.go:1801 +0x724
created by net/http.(*Server).Serve
c:/go/src/net/http/server.go:2720 +0x28f
~~~
#3
更多评论
<a href="/user/channel" title="@channel">@channel</a> 没有错误信息 直接在http无法打开。。
其他的增删改都正常 我这个代码有没有问题 写法
#2