cur = con.cursor()
或利用上下文管理自动关闭游标:
with con.cursor() as cur:
cur.execute('数据库语句')
one_data =cur.fetchone() # fetchone表示获取数据库的一行,fetchall表示所有满足条件的行
while one_data:
print(one_data)
one_data =cur.fetchone()
执行sql语句
res = cur.execute("select * from table_name")
print(cur.fetchmany(3)) #指定条数的数据