Files
goLearn/connectPool/cursor/cursor.go
2025-08-15 03:53:14 +08:00

25 lines
477 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package cursor
import (
"database/sql"
"fmt"
"goLearn/model"
)
func Runcorsor(db *sql.DB) {
row, err := db.Query("SELECT uid,author,age FROM article WHERE age > 50")
if err != nil {
return
}
num := 0
for row.Next() {
num++
var data model.CursorData
err := row.Scan(&data.Uid, &data.Author, &data.Age)
if err != nil {
panic(err)
}
fmt.Printf("第%d个age大于50的数据\nuid: %s\nauthor: %s\nage:%d\n", num, data.Uid, data.Author, data.Age)
}
}