//QueryContext查询一些结果//query:select*fromtestlimit0func(db*DB)QueryContext(ctxcontext.Context,querystring,args...any)(*Rows,error)typeRowsstruct{Close()errorColumnTypes()([]*ColumnType,error)Columns()([]string,error)Err()errorNext()boolNextResultSet()boolScan(dest...any)error}当还有结果的时候(即Rows.Next()==true时),说明还有结果未读取出来,此时必须调用Rows.Close()方法来对流进行关闭以释放连接(让当前连接变为空闲状态以让其他逻辑可以使用该连接)。.实验-不调用Rows.Close()若不调用Close又会怎样呢?下面做一个实验来观察一下:
select*fromuser;+----+-------+---------------------+----------+--------+
id
register_time
password
status
+----+-------+---------------------+----------+--------+
2
dw
20--:0:00
d
0
+----+-------+---------------------+----------+--------+rowinset(0.03sec)
packagemainimport("context""database/sql""encoding/json""fmt""sync""time"_"github.